Search in sources :

Example 1 with Pair

use of com.twitter.heron.common.basics.Pair in project heron by twitter.

the class CommonPackingTests method testScaleDownHomogenousFirst.

@Test
public void testScaleDownHomogenousFirst() throws Exception {
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] initialComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(A, 1, 0)), new Pair<>(1, new InstanceId(A, 2, 1)), new Pair<>(1, new InstanceId(B, 3, 0)), new Pair<>(3, new InstanceId(B, 4, 1)), new Pair<>(3, new InstanceId(B, 5, 2)), new Pair<>(3, new InstanceId(B, 6, 3)), new Pair<>(3, new InstanceId(B, 7, 4)) };
    Map<String, Integer> componentChanges = new HashMap<>();
    componentChanges.put(B, -4);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] expectedComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(A, 1, 0)), new Pair<>(1, new InstanceId(A, 2, 1)), new Pair<>(1, new InstanceId(B, 3, 0)) };
    doScaleDownTest(initialComponentInstances, componentChanges, expectedComponentInstances);
}
Also used : InstanceId(com.twitter.heron.spi.packing.InstanceId) HashMap(java.util.HashMap) Pair(com.twitter.heron.common.basics.Pair) Test(org.junit.Test)

Example 2 with Pair

use of com.twitter.heron.common.basics.Pair in project heron by twitter.

the class PackingPlanBuilderTest method testInvalidContainerRemoveFromPackingPlan.

@Test(expected = PackingException.class)
public void testInvalidContainerRemoveFromPackingPlan() throws ResourceExceededException {
    PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, String>[] removed = new Pair[] { new Pair<>(7, "componentA") };
    PackingTestHelper.removeFromTestPackingPlan(TOPOLOGY_ID, plan, removed, 0);
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Pair(com.twitter.heron.common.basics.Pair) Test(org.junit.Test)

Example 3 with Pair

use of com.twitter.heron.common.basics.Pair in project heron by twitter.

the class ZkUtilsTest method testSetupZkTunnel.

/**
   * Test setupZkTunnel
   */
@Test
public void testSetupZkTunnel() throws Exception {
    String host0 = "host0";
    int port0 = 12;
    InetSocketAddress address0 = NetworkUtils.getInetSocketAddress(String.format("%s:%d", host0, port0));
    String host1 = "host1";
    int port1 = 13;
    InetSocketAddress address1 = NetworkUtils.getInetSocketAddress(String.format("%s:%d", host1, port1));
    String host2 = "host2";
    int port2 = 9049;
    InetSocketAddress address2 = NetworkUtils.getInetSocketAddress(String.format("%s:%d", host2, port2));
    String tunnelHost = "tunnelHost";
    int tunnelPort = 9519;
    InetSocketAddress tunnelAddress = NetworkUtils.getInetSocketAddress(String.format("%s:%d", tunnelHost, tunnelPort));
    // Original connection String
    String connectionString = String.format("%s:%d, %s:%d,  %s:%d   ", host0, port0, host1, port1, host2, port2);
    Config config = mock(Config.class);
    when(config.getStringValue(Key.STATEMGR_CONNECTION_STRING)).thenReturn(connectionString);
    NetworkUtils.TunnelConfig tunnelConfig = NetworkUtils.TunnelConfig.build(config, NetworkUtils.HeronSystem.STATE_MANAGER);
    Process process = mock(Process.class);
    // Mock the invocation of establishSSHTunnelIfNeeded
    // address0 and address1 are directly reachable
    // address2 are reachable after tunneling
    PowerMockito.spy(NetworkUtils.class);
    PowerMockito.doReturn(new Pair<>(address0, process)).when(NetworkUtils.class, "establishSSHTunnelIfNeeded", eq(address0), anyString(), any(NetworkUtils.TunnelType.class), anyInt(), anyInt(), anyInt(), anyInt());
    PowerMockito.doReturn(new Pair<>(address1, process)).when(NetworkUtils.class, "establishSSHTunnelIfNeeded", eq(address1), anyString(), any(NetworkUtils.TunnelType.class), anyInt(), anyInt(), anyInt(), anyInt());
    PowerMockito.doReturn(new Pair<>(tunnelAddress, process)).when(NetworkUtils.class, "establishSSHTunnelIfNeeded", eq(address2), anyString(), any(NetworkUtils.TunnelType.class), anyInt(), anyInt(), anyInt(), anyInt());
    Pair<String, List<Process>> ret = ZkUtils.setupZkTunnel(config, tunnelConfig);
    // Assert with expected results
    String expectedConnectionString = String.format("%s,%s,%s", address0.toString(), address1.toString(), tunnelAddress.toString());
    assertEquals(expectedConnectionString, ret.first);
    assertEquals(3, ret.second.size());
    for (Process p : ret.second) {
        assertEquals(process, p);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Config(com.twitter.heron.spi.common.Config) NetworkUtils(com.twitter.heron.spi.utils.NetworkUtils) List(java.util.List) Mockito.anyString(org.mockito.Mockito.anyString) Pair(com.twitter.heron.common.basics.Pair) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with Pair

use of com.twitter.heron.common.basics.Pair in project incubator-heron by apache.

the class PackingPlanBuilderTest method testExceededCapacityAddingToPackingPlan.

@Test(expected = ResourceExceededException.class)
public void testExceededCapacityAddingToPackingPlan() throws ResourceExceededException {
    PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] added = new Pair[] { new Pair<>(3, new InstanceId("componentB", 4, 1)) };
    PackingTestHelper.addToTestPackingPlan(TOPOLOGY_ID, plan, PackingTestHelper.toContainerIdComponentNames(added), 0);
}
Also used : InstanceId(com.twitter.heron.spi.packing.InstanceId) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Pair(com.twitter.heron.common.basics.Pair) Test(org.junit.Test)

Example 5 with Pair

use of com.twitter.heron.common.basics.Pair in project incubator-heron by apache.

the class PackingPlanBuilderTest method testInvalidContainerRemoveFromPackingPlan.

@Test(expected = PackingException.class)
public void testInvalidContainerRemoveFromPackingPlan() throws ResourceExceededException {
    PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, String>[] removed = new Pair[] { new Pair<>(7, "componentA") };
    PackingTestHelper.removeFromTestPackingPlan(TOPOLOGY_ID, plan, removed, 0);
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Pair(com.twitter.heron.common.basics.Pair) Test(org.junit.Test)

Aggregations

Pair (com.twitter.heron.common.basics.Pair)27 Test (org.junit.Test)18 InstanceId (com.twitter.heron.spi.packing.InstanceId)12 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)12 HashMap (java.util.HashMap)7 InetSocketAddress (java.net.InetSocketAddress)6 Config (com.twitter.heron.spi.common.Config)5 ArrayList (java.util.ArrayList)4 ContainerPlan (com.twitter.heron.spi.packing.PackingPlan.ContainerPlan)2 NetworkUtils (com.twitter.heron.spi.utils.NetworkUtils)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 Before (org.junit.Before)2 Mockito.anyString (org.mockito.Mockito.anyString)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 SubmitDryRunResponse (com.twitter.heron.scheduler.dryrun.SubmitDryRunResponse)1 File (java.io.File)1