Search in sources :

Example 1 with ConfigUtils

use of org.apache.storm.utils.ConfigUtils in project storm by apache.

the class AsyncLocalizerTest method testRequestDownloadTopologyBlobs.

@Test
public void testRequestDownloadTopologyBlobs() throws Exception {
    ConfigUtils mockedConfigUtils = mock(ConfigUtils.class);
    ConfigUtils previousConfigUtils = ConfigUtils.setInstance(mockedConfigUtils);
    AsyncLocalizer victim = null;
    try (TmpPath stormLocal = new TmpPath();
        TmpPath localizerRoot = new TmpPath()) {
        Map<String, Object> conf = new HashMap<>();
        conf.put(Config.STORM_LOCAL_DIR, stormLocal.getPath());
        AdvancedFSOps ops = AdvancedFSOps.make(conf);
        StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
        victim = spy(new AsyncLocalizer(conf, ops, localizerRoot.getPath(), metricsRegistry));
        final String topoId = "TOPO-12345";
        final String user = "user";
        final Path userDir = Paths.get(stormLocal.getPath(), user);
        final Path topologyDirRoot = Paths.get(stormLocal.getPath(), topoId);
        final String simpleLocalName = "simple.txt";
        final String simpleKey = "simple";
        Map<String, Map<String, Object>> topoBlobMap = new HashMap<>();
        Map<String, Object> simple = new HashMap<>();
        simple.put("localname", simpleLocalName);
        simple.put("uncompress", false);
        topoBlobMap.put(simpleKey, simple);
        final int port = 8080;
        Map<String, Object> topoConf = new HashMap<>(conf);
        topoConf.put(Config.TOPOLOGY_BLOBSTORE_MAP, topoBlobMap);
        topoConf.put(Config.TOPOLOGY_NAME, "TOPO");
        List<LocalizedResource> localizedList = new ArrayList<>();
        LocalizedResource simpleLocal = new LocalizedResource(simpleKey, localizerRoot.getFile().toPath(), false, ops, conf, user, metricsRegistry);
        localizedList.add(simpleLocal);
        when(mockedConfigUtils.supervisorStormDistRootImpl(conf, topoId)).thenReturn(topologyDirRoot.toString());
        when(mockedConfigUtils.readSupervisorStormConfImpl(conf, topoId)).thenReturn(topoConf);
        when(mockedConfigUtils.readSupervisorTopologyImpl(conf, topoId, ops)).thenReturn(constructEmptyStormTopology());
        // Write the mocking backwards so the actual method is not called on the spy object
        doReturn(CompletableFuture.supplyAsync(() -> null)).when(victim).requestDownloadBaseTopologyBlobs(any(), eq(null));
        Files.createDirectories(topologyDirRoot);
        doReturn(userDir.toFile()).when(victim).getLocalUserFileCacheDir(user);
        doReturn(localizedList).when(victim).getBlobs(any(List.class), any(), any());
        Future<Void> f = victim.requestDownloadTopologyBlobs(constructLocalAssignment(topoId, user), port, null);
        f.get(20, TimeUnit.SECONDS);
        // We should be done now...
        verify(victim).getLocalUserFileCacheDir(user);
        assertTrue(ops.fileExists(userDir));
        verify(victim).getBlobs(any(List.class), any(), any());
        // symlink was created
        assertTrue(Files.isSymbolicLink(topologyDirRoot.resolve(simpleLocalName)));
    } finally {
        ConfigUtils.setInstance(previousConfigUtils);
        if (victim != null) {
            victim.close();
        }
    }
}
Also used : Path(java.nio.file.Path) TmpPath(org.apache.storm.testing.TmpPath) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TmpPath(org.apache.storm.testing.TmpPath) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) ConfigUtils(org.apache.storm.utils.ConfigUtils) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) List(java.util.List) ArrayList(java.util.ArrayList) AdvancedFSOps(org.apache.storm.daemon.supervisor.AdvancedFSOps) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Test(org.junit.Test)

Example 2 with ConfigUtils

use of org.apache.storm.utils.ConfigUtils in project storm by apache.

the class AsyncLocalizerTest method testRequestDownloadTopologyBlobsLocalMode.

@Test
public void testRequestDownloadTopologyBlobsLocalMode() throws Exception {
    // tests download of topology blobs in local mode on a topology without resources folder
    ConfigUtils mockedConfigUtils = mock(ConfigUtils.class);
    ServerUtils mockedServerUtils = mock(ServerUtils.class);
    ConfigUtils previousConfigUtils = ConfigUtils.setInstance(mockedConfigUtils);
    ServerUtils previousServerUtils = ServerUtils.setInstance(mockedServerUtils);
    AsyncLocalizer victim = null;
    try (TmpPath stormLocal = new TmpPath();
        TmpPath localizerRoot = new TmpPath()) {
        Map<String, Object> conf = new HashMap<>();
        conf.put(Config.STORM_LOCAL_DIR, stormLocal.getPath());
        conf.put(Config.STORM_CLUSTER_MODE, "local");
        StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
        AdvancedFSOps ops = AdvancedFSOps.make(conf);
        victim = spy(new AsyncLocalizer(conf, ops, localizerRoot.getPath(), metricsRegistry));
        final String topoId = "TOPO-12345";
        final String user = "user";
        final int port = 8080;
        final Path userDir = Paths.get(stormLocal.getPath(), user);
        final Path stormRoot = Paths.get(stormLocal.getPath(), topoId);
        final String simpleLocalName = "simple.txt";
        final String simpleKey = "simple";
        Map<String, Map<String, Object>> topoBlobMap = new HashMap<>();
        Map<String, Object> simple = new HashMap<>();
        simple.put("localname", simpleLocalName);
        simple.put("uncompress", false);
        topoBlobMap.put(simpleKey, simple);
        Map<String, Object> topoConf = new HashMap<>(conf);
        topoConf.put(Config.TOPOLOGY_BLOBSTORE_MAP, topoBlobMap);
        topoConf.put(Config.TOPOLOGY_NAME, "TOPO");
        List<LocalizedResource> localizedList = new ArrayList<>();
        LocalizedResource simpleLocal = new LocalizedResource(simpleKey, localizerRoot.getFile().toPath(), false, ops, conf, user, metricsRegistry);
        localizedList.add(simpleLocal);
        when(mockedConfigUtils.supervisorStormDistRootImpl(conf, topoId)).thenReturn(stormRoot.toString());
        when(mockedConfigUtils.readSupervisorStormConfImpl(conf, topoId)).thenReturn(topoConf);
        when(mockedConfigUtils.readSupervisorTopologyImpl(conf, topoId, ops)).thenReturn(constructEmptyStormTopology());
        doReturn(mockBlobStore).when(victim).getClientBlobStore();
        doReturn(userDir.toFile()).when(victim).getLocalUserFileCacheDir(user);
        doReturn(localizedList).when(victim).getBlobs(any(List.class), any(), any());
        ReadableBlobMeta blobMeta = new ReadableBlobMeta();
        blobMeta.set_version(1);
        doReturn(blobMeta).when(mockBlobStore).getBlobMeta(any());
        when(mockBlobStore.getBlob(any())).thenAnswer(invocation -> new TestInputStreamWithMeta(LOCAL_MODE_JAR_VERSION));
        Future<Void> f = victim.requestDownloadTopologyBlobs(constructLocalAssignment(topoId, user), port, null);
        f.get(20, TimeUnit.SECONDS);
        verify(victim).getLocalUserFileCacheDir(user);
        assertTrue(ops.fileExists(userDir));
        verify(victim).getBlobs(any(List.class), any(), any());
        // make sure resources directory after blob version commit is created.
        Path extractionDir = stormRoot.resolve(LocallyCachedTopologyBlob.TopologyBlobType.TOPO_JAR.getExtractionDir());
        assertTrue(ops.fileExists(extractionDir));
    } finally {
        ConfigUtils.setInstance(previousConfigUtils);
        ServerUtils.setInstance(previousServerUtils);
        if (victim != null) {
            victim.close();
        }
    }
}
Also used : Path(java.nio.file.Path) TmpPath(org.apache.storm.testing.TmpPath) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TmpPath(org.apache.storm.testing.TmpPath) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) ConfigUtils(org.apache.storm.utils.ConfigUtils) ArrayList(java.util.ArrayList) ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) ServerUtils(org.apache.storm.utils.ServerUtils) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) List(java.util.List) ArrayList(java.util.ArrayList) AdvancedFSOps(org.apache.storm.daemon.supervisor.AdvancedFSOps) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 AdvancedFSOps (org.apache.storm.daemon.supervisor.AdvancedFSOps)2 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)2 TmpPath (org.apache.storm.testing.TmpPath)2 ConfigUtils (org.apache.storm.utils.ConfigUtils)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ReadableBlobMeta (org.apache.storm.generated.ReadableBlobMeta)1 ServerUtils (org.apache.storm.utils.ServerUtils)1