Skip to content

Commit

Permalink
fix AdminApi test by creating separate mock-pulsar instances for diff…
Browse files Browse the repository at this point in the history
…erent broker (apache#512)
  • Loading branch information
rdhabalia authored Jun 21, 2017
1 parent c7d982b commit 2ca1a7a
Showing 1 changed file with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,7 +36,6 @@
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;
Expand All @@ -53,7 +52,6 @@
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;
Expand All @@ -67,7 +65,6 @@
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;
Expand Down Expand Up @@ -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 {
Expand All @@ -127,16 +123,10 @@ public void setup() throws Exception {

// 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));
Expand All @@ -149,9 +139,7 @@ public void setup() throws Exception {
@Override
public void cleanup() throws Exception {
super.internalCleanup();

otheradmin.close();
otherPulsar.close();
mockPulsarSetup.cleanup();
}

@DataProvider(name = "numBundles")
Expand Down Expand Up @@ -361,7 +349,11 @@ public void clusterNamespaceIsolationPolicies() throws PulsarAdminException {
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)
Expand Down Expand Up @@ -1713,7 +1705,6 @@ public void failed(Throwable e) {
*/
@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;
Expand Down Expand Up @@ -1793,7 +1784,28 @@ public void testIncrementPartitionsOfTopic(String topicName) throws Exception {
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;
}
}

}

0 comments on commit 2ca1a7a

Please sign in to comment.