Search in sources :

Example 41 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class SlurmSchedulerTest method createRunnerConfig.

private static Config createRunnerConfig() {
    Config config = Mockito.mock(Config.class);
    Mockito.when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    Mockito.when(config.getStringValue(Key.CLUSTER)).thenReturn(CLUSTER);
    Mockito.when(config.getStringValue(Key.ROLE)).thenReturn(ROLE);
    Mockito.when(config.getStringValue(Key.ENVIRON)).thenReturn(ENVIRON);
    return config;
}
Also used : Config(com.twitter.heron.spi.common.Config)

Example 42 with Config

use of com.twitter.heron.spi.common.Config 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 43 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class LocalFileSystemConfigTest method testOverrideTopologyDirectory.

@Test
public void testOverrideTopologyDirectory() throws Exception {
    LocalFileSystemUploader uploader = new LocalFileSystemUploader();
    String overrideDirectory = "/users/twitter";
    Config config = Config.toLocalMode(Config.newBuilder().putAll(getDefaultConfig()).put(LocalFileSystemKey.FILE_SYSTEM_DIRECTORY.value(), overrideDirectory).build());
    uploader.initialize(config);
    Assert.assertEquals(uploader.getTopologyDirectory(), overrideDirectory);
}
Also used : Config(com.twitter.heron.spi.common.Config) Test(org.junit.Test)

Example 44 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class LocalFileSystemConfigTest method testTopologyFile.

@Test
public void testTopologyFile() throws Exception {
    Config config = Config.toLocalMode(getDefaultConfig());
    LocalFileSystemUploader uploader = new LocalFileSystemUploader();
    uploader.initialize(config);
    Assert.assertEquals(Paths.get(uploader.getTopologyFile()).getParent().toString(), LocalFileSystemContext.fileSystemDirectory(config));
}
Also used : Config(com.twitter.heron.spi.common.Config) Test(org.junit.Test)

Example 45 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class LocalFileSystemConfigTest method testOverrideTopologyFile.

@Test
public void testOverrideTopologyFile() throws Exception {
    LocalFileSystemUploader uploader = new LocalFileSystemUploader();
    String overrideDirectory = "/users/twitter";
    Config config = Config.toLocalMode(Config.newBuilder().putAll(getDefaultConfig()).put(LocalFileSystemKey.FILE_SYSTEM_DIRECTORY.value(), overrideDirectory).build());
    uploader.initialize(config);
    Assert.assertEquals(Paths.get(uploader.getTopologyFile()).getParent().toString(), overrideDirectory);
}
Also used : Config(com.twitter.heron.spi.common.Config) Test(org.junit.Test)

Aggregations

Config (com.twitter.heron.spi.common.Config)87 Test (org.junit.Test)55 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)31 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)23 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)20 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)17 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)9 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)8 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)8 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)7 Before (org.junit.Before)7 HashSet (java.util.HashSet)5 ByteAmount (com.twitter.heron.common.basics.ByteAmount)4 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)4 PackingException (com.twitter.heron.spi.packing.PackingException)4 Resource (com.twitter.heron.spi.packing.Resource)4 URI (java.net.URI)4 Properties (java.util.Properties)4 CommandLine (org.apache.commons.cli.CommandLine)4 HeronTopology (com.twitter.heron.api.HeronTopology)3