use of org.apache.pulsar.metadata.coordination.impl.CoordinationServiceImpl in project pulsar by apache.
the class DistributedIdGeneratorTest method setup.
@BeforeMethod(alwaysRun = true)
public void setup() throws Exception {
store = MetadataStoreExtended.create("memory:local", MetadataStoreConfig.builder().build());
coordinationService = new CoordinationServiceImpl(store);
}
use of org.apache.pulsar.metadata.coordination.impl.CoordinationServiceImpl in project pulsar by apache.
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 = OrderedScheduler.newSchedulerBuilder().numThreads(1).name("test").build();
zookeeperServer = new ZookeeperServerTest(0);
zookeeperServer.start();
store = MetadataStoreExtended.create(zookeeperServer.getHostPort(), MetadataStoreConfig.builder().sessionTimeoutMillis(5000).build());
coordinationService = new CoordinationServiceImpl(store);
otherStore = MetadataStoreExtended.create(zookeeperServer.getHostPort(), MetadataStoreConfig.builder().sessionTimeoutMillis(5000).build());
when(pulsar.getConfigurationMetadataStore()).thenReturn(store);
when(pulsar.getLocalMetadataStore()).thenReturn(store);
when(pulsar.getConfigurationMetadataStore()).thenReturn(store);
when(pulsar.getCoordinationService()).thenReturn(coordinationService);
bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
nsService = mock(NamespaceService.class);
brokerService = mock(BrokerService.class);
doReturn(CompletableFuture.completedFuture(1)).when(brokerService).unloadServiceUnit(any(), anyBoolean(), anyLong(), any());
doReturn(config).when(pulsar).getConfiguration();
doReturn(nsService).when(pulsar).getNamespaceService();
doReturn(Optional.of(port)).when(config).getBrokerServicePort();
doReturn(Optional.empty()).when(config).getWebServicePort();
doReturn(brokerService).when(pulsar).getBrokerService();
doReturn(selfBrokerUrl).when(pulsar).getBrokerServiceUrl();
}
use of org.apache.pulsar.metadata.coordination.impl.CoordinationServiceImpl in project pulsar by apache.
the class LeaderElectionTest method leaderNodeIsDeletedExternally.
@Test(dataProvider = "impl")
public void leaderNodeIsDeletedExternally(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
@Cleanup CoordinationService coordinationService = new CoordinationServiceImpl(store);
BlockingQueue<LeaderElectionState> notifications = new LinkedBlockingDeque<>();
@Cleanup LeaderElection<String> leaderElection = coordinationService.getLeaderElection(String.class, "/my/leader-election", t -> {
notifications.add(t);
});
LeaderElectionState les = leaderElection.elect("test-1").join();
assertEquals(les, LeaderElectionState.Leading);
assertEquals(notifications.poll(3, TimeUnit.SECONDS), LeaderElectionState.Leading);
store.delete("/my/leader-election", Optional.empty()).join();
assertEquals(notifications.poll(3, TimeUnit.SECONDS), LeaderElectionState.Leading);
assertEquals(les, LeaderElectionState.Leading);
}
use of org.apache.pulsar.metadata.coordination.impl.CoordinationServiceImpl in project pulsar by apache.
the class LeaderElectionTest method revalidateLeaderWithDifferentSessionsSameValue.
@Test(dataProvider = "impl")
public void revalidateLeaderWithDifferentSessionsSameValue(String provider, Supplier<String> urlSupplier) throws Exception {
if (provider.equals("Memory") || provider.equals("RocksDB")) {
// There are no multiple sessions for the local memory provider
return;
}
@Cleanup MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
@Cleanup MetadataStoreExtended store2 = MetadataStoreExtended.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
String path = newKey();
@Cleanup CoordinationService cs = new CoordinationServiceImpl(store);
@Cleanup LeaderElection<String> le = cs.getLeaderElection(String.class, path, __ -> {
});
store2.put(path, ObjectMapperFactory.getThreadLocal().writeValueAsBytes("test-1"), Optional.of(-1L), EnumSet.of(CreateOption.Ephemeral)).join();
LeaderElectionState les = le.elect("test-1").join();
assertEquals(les, LeaderElectionState.Leading);
assertEquals(le.getLeaderValue().join(), Optional.of("test-1"));
assertEquals(le.getLeaderValueIfPresent(), Optional.of("test-1"));
}
use of org.apache.pulsar.metadata.coordination.impl.CoordinationServiceImpl in project pulsar by apache.
the class LeaderElectionTest method basicTest.
@Test(dataProvider = "impl")
public void basicTest(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
@Cleanup CoordinationService coordinationService = new CoordinationServiceImpl(store);
MetadataCache<String> cache = store.getMetadataCache(String.class);
BlockingQueue<LeaderElectionState> notifications = new LinkedBlockingDeque<>();
@Cleanup LeaderElection<String> leaderElection = coordinationService.getLeaderElection(String.class, "/my/leader-election", t -> {
notifications.add(t);
});
assertEquals(cache.get("/my/leader-election").join(), Optional.empty());
LeaderElectionState les = leaderElection.elect("test-1").join();
assertEquals(les, LeaderElectionState.Leading);
assertEquals(notifications.poll(3, TimeUnit.SECONDS), LeaderElectionState.Leading);
assertEquals(cache.get("/my/leader-election").join(), Optional.of("test-1"));
leaderElection.close();
assertEquals(cache.get("/my/leader-election").join(), Optional.empty());
}
Aggregations