use of org.apache.storm.localizer.LocalizedResource in project storm by apache.
the class AsyncLocalizerTest method testRequestDownloadTopologyBlobs.
@Test
public void testRequestDownloadTopologyBlobs() throws Exception {
final String topoId = "TOPO-12345";
LocalAssignment la = new LocalAssignment();
la.set_topology_id(topoId);
ExecutorInfo ei = new ExecutorInfo();
ei.set_task_start(1);
ei.set_task_end(1);
la.add_to_executors(ei);
final String topoName = "TOPO";
final int port = 8080;
final String user = "user";
final String simpleLocalName = "simple.txt";
final String simpleKey = "simple";
final String stormLocal = "/tmp/storm-local/";
final File userDir = new File(stormLocal, user);
final String stormRoot = stormLocal + topoId + "/";
final String localizerRoot = "/tmp/storm-localizer/";
final String simpleLocalFile = localizerRoot + user + "/simple";
final String simpleCurrentLocalFile = localizerRoot + user + "/simple.current";
final StormTopology st = new StormTopology();
st.set_spouts(new HashMap<>());
st.set_bolts(new HashMap<>());
st.set_state_spouts(new HashMap<>());
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> conf = new HashMap<>();
conf.put(Config.STORM_LOCAL_DIR, stormLocal);
Localizer localizer = mock(Localizer.class);
AdvancedFSOps ops = mock(AdvancedFSOps.class);
ConfigUtils mockedCU = mock(ConfigUtils.class);
Utils mockedU = mock(Utils.class);
Map<String, Object> topoConf = new HashMap<>(conf);
topoConf.put(Config.TOPOLOGY_BLOBSTORE_MAP, topoBlobMap);
topoConf.put(Config.TOPOLOGY_SUBMITTER_USER, user);
topoConf.put(Config.TOPOLOGY_NAME, topoName);
List<LocalizedResource> localizedList = new ArrayList<>();
LocalizedResource simpleLocal = new LocalizedResource(simpleKey, simpleLocalFile, false);
localizedList.add(simpleLocal);
AsyncLocalizer al = new AsyncLocalizer(conf, localizer, ops);
ConfigUtils orig = ConfigUtils.setInstance(mockedCU);
Utils origUtils = Utils.setInstance(mockedU);
try {
when(mockedCU.supervisorStormDistRootImpl(conf, topoId)).thenReturn(stormRoot);
when(mockedCU.readSupervisorStormConfImpl(conf, topoId)).thenReturn(topoConf);
when(mockedCU.readSupervisorTopologyImpl(conf, topoId, ops)).thenReturn(st);
when(localizer.getLocalUserFileCacheDir(user)).thenReturn(userDir);
when(localizer.getBlobs(any(List.class), eq(user), eq(topoName), eq(userDir))).thenReturn(localizedList);
Future<Void> f = al.requestDownloadTopologyBlobs(la, port);
f.get(20, TimeUnit.SECONDS);
// We should be done now...
verify(localizer).getLocalUserFileCacheDir(user);
verify(ops).fileExists(userDir);
verify(ops).forceMkdir(userDir);
verify(localizer).getBlobs(any(List.class), eq(user), eq(topoName), eq(userDir));
verify(ops).createSymlink(new File(stormRoot, simpleLocalName), new File(simpleCurrentLocalFile));
} finally {
al.shutdown();
ConfigUtils.setInstance(orig);
Utils.setInstance(origUtils);
}
}
Aggregations