提交 2ca1a7a9 编写于 作者: R Rajan 提交者: GitHub

fix AdminApi test by creating separate mock-pulsar instances for different broker (#512)

上级 c7d982be
......@@ -16,8 +16,8 @@
package com.yahoo.pulsar.broker.admin;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
......@@ -36,7 +36,6 @@ import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.InvocationCallback;
import javax.ws.rs.client.WebTarget;
import org.apache.bookkeeper.test.PortManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
......@@ -53,7 +52,6 @@ import com.google.common.collect.Sets;
import com.google.common.hash.Hashing;
import com.yahoo.pulsar.broker.PulsarServerException;
import com.yahoo.pulsar.broker.PulsarService;
import com.yahoo.pulsar.broker.ServiceConfiguration;
import com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest;
import com.yahoo.pulsar.broker.namespace.NamespaceEphemeralData;
import com.yahoo.pulsar.broker.namespace.NamespaceService;
......@@ -67,7 +65,6 @@ import com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedExce
import com.yahoo.pulsar.client.admin.internal.LookupImpl;
import com.yahoo.pulsar.client.admin.internal.PersistentTopicsImpl;
import com.yahoo.pulsar.client.admin.internal.PropertiesImpl;
import com.yahoo.pulsar.client.api.Authentication;
import com.yahoo.pulsar.client.api.ClientConfiguration;
import com.yahoo.pulsar.client.api.Consumer;
import com.yahoo.pulsar.client.api.ConsumerConfiguration;
......@@ -108,15 +105,14 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
private static final Logger LOG = LoggerFactory.getLogger(AdminApiTest.class);
private MockedPulsarService mockPulsarSetup;
private PulsarService otherPulsar;
private PulsarAdmin otheradmin;
private NamespaceBundleFactory bundleFactory;
private final int SECONDARY_BROKER_PORT = PortManager.nextFreePort();
private final int SECONDARY_BROKER_WEBSERVICE_PORT = PortManager.nextFreePort();
@BeforeMethod
@Override
public void setup() throws Exception {
......@@ -127,16 +123,10 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
// create otherbroker to test redirect on calls that need
// namespace ownership
ServiceConfiguration otherconfig = new ServiceConfiguration();
otherconfig.setBrokerServicePort(SECONDARY_BROKER_PORT);
otherconfig.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
otherconfig.setLoadBalancerEnabled(false);
otherconfig.setClusterName("test");
otherPulsar = startBroker(otherconfig);
otheradmin = new PulsarAdmin(new URL("http://127.0.0.1" + ":" + SECONDARY_BROKER_WEBSERVICE_PORT),
(Authentication) null);
mockPulsarSetup = new MockedPulsarService();
mockPulsarSetup.setup();
otherPulsar = mockPulsarSetup.getPulsar();
otheradmin = mockPulsarSetup.getAdmin();
// Setup namespaces
admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
......@@ -149,9 +139,7 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
@Override
public void cleanup() throws Exception {
super.internalCleanup();
otheradmin.close();
otherPulsar.close();
mockPulsarSetup.cleanup();
}
@DataProvider(name = "numBundles")
......@@ -361,7 +349,11 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
public void brokers() throws Exception {
List<String> list = admin.brokers().getActiveBrokers("use");
Assert.assertNotNull(list);
Assert.assertEquals(list.size(), 2);
Assert.assertEquals(list.size(), 1);
List<String> list2 = otheradmin.brokers().getActiveBrokers("test");
Assert.assertNotNull(list2);
Assert.assertEquals(list2.size(), 1);
Map<String, NamespaceOwnershipStatus> nsMap = admin.brokers().getOwnedNamespaces("use", list.get(0));
// since sla-monitor ns is not created nsMap.size() == 1 (for HeartBeat Namespace)
......@@ -1713,7 +1705,6 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
*/
@Test(dataProvider = "topicName")
public void testIncrementPartitionsOfTopic(String topicName) throws Exception {
final String subName1 = topicName + "-my-sub 1";
final String subName2 = topicName + "-my-sub 2";
final int startPartitions = 4;
......@@ -1793,7 +1784,28 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
consumer1.close();
consumer2.close();
consumer2.close();
}
class MockedPulsarService extends MockedPulsarServiceBaseTest {
@Override
protected void setup() throws Exception {
conf.setLoadBalancerEnabled(false);
conf.setClusterName("test");
super.internalSetup();
}
@Override
protected void cleanup() throws Exception {
super.internalCleanup();
}
public PulsarService getPulsar() {
return pulsar;
}
public PulsarAdmin getAdmin() {
return admin;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册