Search in sources :

Example 21 with ZooKeeperConnectionManager

use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.

the class ZookeeperConnectionManagerTest method testMarkUpAndDownMultipleTimesFinalDown.

@Test(invocationCount = 10, timeOut = 10000)
public void testMarkUpAndDownMultipleTimesFinalDown() throws Exception {
    ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
    ZooKeeperConnectionManager manager = createManager(true, announcer);
    // set up many concurrent callbacks
    FutureCallback<None> allMarkupsDownsSucceed = new FutureCallback<>();
    int count = 1;
    Callback<None> markUpAllServersCallback = new MultiCallback(allMarkupsDownsSucceed, count * 2);
    ExecutorService executorService = Executors.newScheduledThreadPool(100);
    for (int i = 0; i < count; i++) {
        executorService.execute(() -> {
            manager.markUpAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
            manager.markDownAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
        });
    }
    allMarkupsDownsSucceed.get();
    // data validation
    ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
    AssertionMethods.assertWithTimeout(1000, () -> {
        UriProperties properties = store.get(_cluster);
        assertNotNull(properties);
        assertNull(properties.getPartitionDataMap(URI.create(_uri)), _uri);
    });
    shutdownManager(manager);
    executorService.shutdown();
}
Also used : UriProperties(com.linkedin.d2.balancer.properties.UriProperties) ExecutorService(java.util.concurrent.ExecutorService) MultiCallback(com.linkedin.common.callback.MultiCallback) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Example 22 with ZooKeeperConnectionManager

use of com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager in project rest.li by linkedin.

the class ZookeeperConnectionManagerTest method testMarkUpWithMultiPartition.

@Test
public void testMarkUpWithMultiPartition() throws Exception {
    double newWeight = 10d;
    ZooKeeperAnnouncer announcer = getZooKeeperMultiPartitionAnnouncer(_cluster, _uri, PARTITION1_ID, PARTITION2_ID, PARTITION1_WEIGHT, PARTITION2_WEIGHT);
    try {
        announcer.setWeight(newWeight);
        Assert.fail("The operation should not be supported since we don't know for which partition we should change weight for.");
    } catch (IllegalArgumentException ex) {
    // Success
    }
    ZooKeeperConnectionManager manager = createManager(true, announcer);
    ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
    UriProperties properties = store.get(_cluster);
    assertNotNull(properties);
    assertNotEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION1_ID).getWeight(), newWeight);
    assertNotEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION2_ID).getWeight(), newWeight);
    assertNull(properties.getPartitionDataMap(URI.create(_uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID));
    assertEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION1_ID).getWeight(), PARTITION1_WEIGHT);
    assertEquals(properties.getPartitionDataMap(URI.create(_uri)).get(PARTITION2_ID).getWeight(), PARTITION2_WEIGHT);
    assertEquals(properties.Uris().size(), 1);
    shutdownManager(manager);
}
Also used : UriProperties(com.linkedin.d2.balancer.properties.UriProperties) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)16 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)15 FutureCallback (com.linkedin.common.callback.FutureCallback)12 None (com.linkedin.common.util.None)12 ZooKeeperConnectionManager (com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager)11 URI (java.net.URI)6 HashMap (java.util.HashMap)4 ExecutionException (java.util.concurrent.ExecutionException)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ExecutorService (java.util.concurrent.ExecutorService)3 TimeoutException (java.util.concurrent.TimeoutException)3 MultiCallback (com.linkedin.common.callback.MultiCallback)2 D2Client (com.linkedin.d2.balancer.D2Client)2 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)2 ZooKeeperAnnouncer (com.linkedin.d2.balancer.servers.ZooKeeperAnnouncer)2 ZKPersistentConnection (com.linkedin.d2.discovery.stores.zk.ZKPersistentConnection)2 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)2 List (java.util.List)2 Random (java.util.Random)2