use of com.yahoo.pulsar.common.naming.NamespaceBundleFactory in project pulsar by yahoo.
the class AdminApiTest method setup.
@BeforeMethod
@Override
public void setup() throws Exception {
conf.setLoadBalancerEnabled(true);
super.internalSetup();
bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
// 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);
// Setup namespaces
admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
PropertyAdmin propertyAdmin = new PropertyAdmin(Lists.newArrayList("role1", "role2"), Sets.newHashSet("use"));
admin.properties().createProperty("prop-xyz", propertyAdmin);
admin.namespaces().createNamespace("prop-xyz/use/ns1");
}
use of com.yahoo.pulsar.common.naming.NamespaceBundleFactory in project pulsar by yahoo.
the class OwnershipCacheTest method setup.
@BeforeMethod
public void setup() throws Exception {
final int port = 8080;
selfBrokerUrl = "tcp://localhost:" + port;
pulsar = mock(PulsarService.class);
config = mock(ServiceConfiguration.class);
executor = new OrderedSafeExecutor(1, "test");
zkCache = new LocalZooKeeperCache(MockZooKeeper.newInstance(), executor);
localCache = new LocalZooKeeperCacheService(zkCache, null);
bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
nsService = mock(NamespaceService.class);
brokerService = mock(BrokerService.class);
doReturn(CompletableFuture.completedFuture(1)).when(brokerService).unloadServiceUnit(anyObject());
doReturn(zkCache).when(pulsar).getLocalZkCache();
doReturn(localCache).when(pulsar).getLocalZkCacheService();
doReturn(config).when(pulsar).getConfiguration();
doReturn(nsService).when(pulsar).getNamespaceService();
doReturn(port).when(config).getBrokerServicePort();
doReturn(brokerService).when(pulsar).getBrokerService();
doReturn(webAddress(config)).when(pulsar).getWebServiceAddress();
doReturn(selfBrokerUrl).when(pulsar).getBrokerServiceUrl();
}
use of com.yahoo.pulsar.common.naming.NamespaceBundleFactory in project pulsar by yahoo.
the class ResourceQuotaCacheTest method setup.
@BeforeMethod
public void setup() throws Exception {
pulsar = mock(PulsarService.class);
OrderedSafeExecutor executor = new OrderedSafeExecutor(1, "test");
zkCache = new LocalZooKeeperCache(MockZooKeeper.newInstance(), executor);
localCache = new LocalZooKeeperCacheService(zkCache, null);
bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
doReturn(zkCache).when(pulsar).getLocalZkCache();
doReturn(localCache).when(pulsar).getLocalZkCacheService();
}
use of com.yahoo.pulsar.common.naming.NamespaceBundleFactory in project pulsar by yahoo.
the class NamespaceServiceTest method testSplitAndOwnBundles.
@Test
public void testSplitAndOwnBundles() throws Exception {
OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
ownership.setAccessible(true);
ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
NamespaceService namespaceService = pulsar.getNamespaceService();
NamespaceName nsname = new NamespaceName("pulsar/global/ns1");
DestinationName dn = DestinationName.get("persistent://pulsar/global/ns1/topic-1");
NamespaceBundles bundles = namespaceService.getNamespaceBundleFactory().getBundles(nsname);
NamespaceBundle originalBundle = bundles.findBundle(dn);
// Split bundle and take ownership of split bundles
CompletableFuture<Void> result = namespaceService.splitAndOwnBundle(originalBundle);
try {
result.get();
} catch (Exception e) {
// make sure: no failure
fail("split bundle faild", e);
}
NamespaceBundleFactory bundleFactory = this.pulsar.getNamespaceService().getNamespaceBundleFactory();
NamespaceBundles updatedNsBundles = bundleFactory.getBundles(nsname);
// new updated bundles shouldn't be null
assertNotNull(updatedNsBundles);
List<NamespaceBundle> bundleList = updatedNsBundles.getBundles();
assertNotNull(bundles);
NamespaceBundleFactory utilityFactory = NamespaceBundleFactory.createFactory(Hashing.crc32());
// (1) validate bundleFactory-cache has newly split bundles and removed old parent bundle
Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles = splitBundles(utilityFactory, nsname, bundles, originalBundle);
assertNotNull(splitBundles);
Set<NamespaceBundle> splitBundleSet = new HashSet<>(splitBundles.getRight());
splitBundleSet.removeAll(bundleList);
assertTrue(splitBundleSet.isEmpty());
// (2) validate LocalZookeeper policies updated with newly created split
// bundles
String path = joinPath(LOCAL_POLICIES_ROOT, nsname.toString());
byte[] content = this.pulsar.getLocalZkCache().getZooKeeper().getData(path, null, new Stat());
Policies policies = ObjectMapperFactory.getThreadLocal().readValue(content, Policies.class);
NamespaceBundles localZkBundles = bundleFactory.getBundles(nsname, policies.bundles);
assertTrue(updatedNsBundles.equals(localZkBundles));
log.info("Policies: {}", policies);
// (3) validate ownership of new split bundles by local owner
bundleList.stream().forEach(b -> {
try {
byte[] data = this.pulsar.getLocalZkCache().getZooKeeper().getData(ServiceUnitZkUtils.path(b), null, new Stat());
NamespaceEphemeralData node = ObjectMapperFactory.getThreadLocal().readValue(data, NamespaceEphemeralData.class);
Assert.assertEquals(node.getNativeUrl(), this.pulsar.getBrokerServiceUrl());
} catch (Exception e) {
fail("failed to setup ownership", e);
}
});
}
Aggregations