public void untilZookeeperPathIsCreated(String... path) { untilZookeeperPathIsCreated(stream(path).collect(joining("/"))); }
public void untilZookeeperPathIsCreated(String... path) { untilZookeeperPathIsCreated(stream(path).collect(joining("/"))); }
@Test public void shouldIncrementAndRetrieveCounterValue() { // given when counter.increment("/increment/host/metric", 10); wait.untilZookeeperPathIsCreated("/increment/host/metric"); // then assertThat(counter.getValue("/increment", "/metric")).isEqualTo(10); assertThat(counter.countOccurrences("/increment", "/metric")).isEqualTo(1); }
@Test public void shouldIncrementAndRetrieveCounterForGivenPath() { // given when counter.increment("/increment", 10); wait.untilZookeeperPathIsCreated("/increment"); // then assertThat(counter.getValue("/increment")).isEqualTo(10); }
@Test public void shouldReturnSumOfAllNodeChildrenValues() { // given when counter.increment("/sum/host1/metric", 10); counter.increment("/sum/host2/metric", 5); wait.untilZookeeperPathIsCreated("/sum/host1/metric"); // then assertThat(counter.getValue("/sum", "/metric")).isEqualTo(15); }
@Test public void shouldResetNodeWhenConnectionIsClosed() { // given try (CuratorFramework otherClient = newClient()) { DistributedEphemeralCounter otherCounter = new DistributedEphemeralCounter(otherClient); otherCounter.increment("/ephemeral/host1/metric", 10); wait.untilZookeeperPathIsCreated("/ephemeral/host1/metric"); } // when counter.increment("/ephemeral/host2/metric", 5); wait.untilZookeeperPathIsCreated("/ephemeral/host2/metric"); // then assertThat(counter.getValue("/ephemeral", "/metric")).isEqualTo(5); } }
private Subscription forceAssignment(Subscription sub) { workTracker.forceAssignment(sub); wait.untilZookeeperPathIsCreated(basePath, sub.getQualifiedName().toString(), supervisorId); return sub; }
@Test public void shouldIncrementCounterAtomicallyWhenIncrementedConcurrently() { // given SharedCounter otherCounter = new SharedCounter(zookeeperClient, 72 * 3600, 1000, 3); // when counter.increment("/sharedIncrement", 10); otherCounter.increment("/sharedIncrement", 15); wait.untilZookeeperPathIsCreated("/sharedIncrement"); // then assertThat(counter.getValue("/sharedIncrement")).isEqualTo(25); }
@Test public void shouldApplyAssignmentChangesByAddingNewNodes() { // given Subscription s1 = forceAssignment(anySubscription()); Subscription s2 = forceAssignment(anySubscription()); SubscriptionAssignmentView view = new SubscriptionAssignmentView( ImmutableMap.of( s1.getQualifiedName(), ImmutableSet.of(assignment(supervisorId, s1.getQualifiedName()), assignment("otherConsumer", s1.getQualifiedName())), s2.getQualifiedName(), ImmutableSet.of(assignment(supervisorId, s2.getQualifiedName())))); // when workTracker.apply(subscriptionAssignmentRegistry.createSnapshot(), view); // then wait.untilZookeeperPathIsCreated(basePath, s1.getQualifiedName().toString(), supervisorId); wait.untilZookeeperPathIsCreated(basePath, s1.getQualifiedName().toString(), "otherConsumer"); wait.untilZookeeperPathIsCreated(basePath, s2.getQualifiedName().toString(), supervisorId); }
@Test public void shouldApplyAssignmentChangesCreatingNewNodesInZookeeper() { // given Subscription s1 = anySubscription(); SubscriptionAssignmentView view = stateWithSingleAssignment(s1); // when workTracker.apply(subscriptionAssignmentRegistry.createSnapshot(), view); // then wait.untilZookeeperPathIsCreated(basePath, s1.getQualifiedName().toString(), supervisorId); }
@Test public void shouldWriteAndReadMaxRateProperly() throws Exception { // given ConsumerInstance consumer1 = consumer("consumer1"); ConsumerInstance consumer2 = consumer("consumer2"); // when maxRateRegistry.update(subscription, ImmutableMap.of( "consumer1", new MaxRate(350.0), "consumer2", new MaxRate(0.5) )); wait.untilZookeeperPathIsCreated( zookeeperPaths.consumersMaxRatePath(cluster, consumer1.getSubscription(), consumer1.getConsumerId())); wait.untilZookeeperPathIsCreated( zookeeperPaths.consumersMaxRatePath(cluster, consumer2.getSubscription(), consumer2.getConsumerId())); // then assertEquals(new MaxRate(350.0), maxRateRegistry.getMaxRate(consumer1).get()); assertEquals(new MaxRate(0.5), maxRateRegistry.getMaxRate(consumer2).get()); }
@Test public void shouldRemoveInactiveConsumerEntries() throws Exception { // given ConsumerInstance consumer1 = consumer("consumer1"); ConsumerInstance consumer2 = consumer("consumer2"); maxRateRegistry.ensureCorrectAssignments(subscription, Sets.newHashSet("consumer1", "consumer2")); maxRateRegistry.update(subscription, ImmutableMap.of( "consumer1", new MaxRate(350.0), "consumer2", new MaxRate(0.5) )); wait.untilZookeeperPathIsCreated( zookeeperPaths.consumersMaxRatePath(cluster, consumer1.getSubscription(), consumer1.getConsumerId())); wait.untilZookeeperPathIsCreated( zookeeperPaths.consumersMaxRatePath(cluster, consumer2.getSubscription(), consumer2.getConsumerId())); // when maxRateRegistry.ensureCorrectAssignments(subscription, Sets.newHashSet("consumer1", "consumer3")); wait.untilZookeeperPathNotExists( zookeeperPaths.consumersRatePath(cluster, consumer2.getSubscription(), consumer2.getConsumerId())); // then assertEquals(Optional.empty(), maxRateRegistry.getMaxRate(consumer2)); }
@Test public void shouldWriteAndReadRateHistoryProperly() throws Exception { // given ConsumerInstance consumer = consumer("consumer1"); RateHistory rateHistory = RateHistory.create(0.5); // when maxRateRegistry.writeRateHistory(consumer, rateHistory); wait.untilZookeeperPathIsCreated( zookeeperPaths.consumersRateHistoryPath(cluster, consumer.getSubscription(), consumer.getConsumerId())); // then assertEquals(rateHistory, maxRateRegistry.getRateHistory(consumer)); }
@Test public void shouldApplyAssignmentChangesByRemovingSubscriptionNode() { // given Subscription s1 = anySubscription(); SubscriptionAssignmentView view = stateWithSingleAssignment(s1); workTracker.apply(subscriptionAssignmentRegistry.createSnapshot(), view); wait.untilZookeeperPathIsCreated(basePath, s1.getQualifiedName().toString(), supervisorId); // when workTracker.apply(subscriptionAssignmentRegistry.createSnapshot(), stateWithNoAssignments()); // then wait.untilZookeeperPathNotExists(basePath, s1.getQualifiedName().toString()); }