private void initializeRegistry() { try { final List<Object> providers = registryHelper.readEntries(registryRoot, newFilter(PROVIDER_SUFFIX)); providers.forEach(provider -> super.registerProvider((Provider) provider)); final List<Object> runtimes = registryHelper.readEntries(registryRoot, newFilter(RUNTIME_SUFFIX)); runtimes.forEach(runtime -> super.registerRuntime((Runtime) runtime)); } catch (Exception e) { logger.error("An error was produced during " + VFSRuntimeRegistry.class.getName() + " initialization.", e); } }
private void initializeRegistry() { try { final List<Object> traces = registryHelper.readEntries(registryRoot, newFilter(TRACE_SUFFIX)); traces.forEach(trace -> super.register((PipelineExecutorTrace) trace)); } catch (Exception e) { logger.error("An error was produced during " + VFSPipelineExecutorRegistry.class.getName() + " initialization.", e); } }
@Test public void testReadEntries() throws Exception { prepareReadEntries(); List<Object> result = registryHelper.readEntries(rootPath, filter); assertEquals(expectedObjects, result); for (Path path : entryPaths) { verify(registryHelper, times(1)).readEntry(path); } }
@Test public void testReadEntriesWithError() throws Exception { prepareReadEntries(); //make an arbitrary path reading to fail. int failingIndex = 5; when(marshaller.unmarshal(entries.get(failingIndex).getContent())).thenThrow(new IOException(ERROR_MESSAGE)); expectedException.expectMessage(ERROR_MESSAGE); registryHelper.readEntries(rootPath, filter); for (int i = 0; i < failingIndex; i++) { verify(registryHelper, times(1)); } }
@Test public void testReadEntries() throws Exception { prepareReadEntries(); List<Object> result = registryHelper.readEntries(rootPath, filter); assertEquals(expectedObjects, result); for (Path path : entryPaths) { verify(registryHelper, times(1)).readEntry(path); } }
@Test public void testReadEntriesWithError() throws Exception { prepareReadEntries(); //make an arbitrary path reading to fail. int failingIndex = 5; when(marshaller.unmarshal(entries.get(failingIndex).getContent())).thenThrow(new IOException(ERROR_MESSAGE)); expectedException.expectMessage(ERROR_MESSAGE); registryHelper.readEntries(rootPath, filter); for (int i = 0; i < failingIndex; i++) { verify(registryHelper, times(1)); } }
@Test public void testInit() throws Exception { providers = new ArrayList<>(); providers.addAll(mockProviderListSPI(providerType, ELEMENTS_COUNT)); runtimes = new ArrayList<>(); runtimes.addAll(mockRuntimeList(providerId, "", ELEMENTS_COUNT)); when(registryHelper.readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(PROVIDER_SUFFIX))).thenReturn(providers); when(registryHelper.readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(RUNTIME_SUFFIX))).thenReturn(runtimes); ((VFSRuntimeRegistry) runtimeRegistry).init(); verify(registryHelper, times(2)).ensureDirectory(RUNTIME_REGISTRY_PATH); verify(registryHelper, times(2)).readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(PROVIDER_SUFFIX)); verify(registryHelper, times(2)).readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(RUNTIME_SUFFIX)); for (Object provider : providers) { verifyProviderIsRegistered((Provider) provider); } for (Object runtime : runtimes) { verifyRuntimeIsRegistered((Runtime) runtime); } }
@Test public void testInit() throws Exception { providers = new ArrayList<>(); providers.addAll(mockProviderListSPI(providerType, ELEMENTS_COUNT)); runtimes = new ArrayList<>(); runtimes.addAll(mockRuntimeList(providerId, "", ELEMENTS_COUNT)); when(registryHelper.readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(PROVIDER_SUFFIX))).thenReturn(providers); when(registryHelper.readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(RUNTIME_SUFFIX))).thenReturn(runtimes); ((VFSRuntimeRegistry) runtimeRegistry).init(); verify(registryHelper, times(2)).ensureDirectory(RUNTIME_REGISTRY_PATH); verify(registryHelper, times(2)).readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(PROVIDER_SUFFIX)); verify(registryHelper, times(2)).readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(RUNTIME_SUFFIX)); for (Object provider : providers) { verifyProviderIsRegistered((Provider) provider); } for (Object runtime : runtimes) { verifyRuntimeIsRegistered((Runtime) runtime); } }
@Test public void testInit() throws Exception { traces = new ArrayList<>(); for (int i = 0; i < TRACES_COUNT; i++) { PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class); when(trace.getTaskId()).thenReturn(PIPELINE_EXECUTION_ID + Integer.toString(i)); traces.add(trace); } when(registryHelper.readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(TRACE_SUFFIX))).thenReturn(traces); ((VFSPipelineExecutorRegistry) pipelineExecutorRegistry).init(); verify(registryHelper, times(2)).ensureDirectory(PIPELINE_EXECUTOR_REGISTRY_PATH); verify(registryHelper, times(2)).readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(TRACE_SUFFIX)); for (Object trace : traces) { PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(((PipelineExecutorTrace) trace).getTaskId()); assertNotNull(result); assertEquals(trace, result); } }
@Test public void testInit() throws Exception { traces = new ArrayList<>(); for (int i = 0; i < TRACES_COUNT; i++) { PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class); when(trace.getTaskId()).thenReturn(PIPELINE_EXECUTION_ID + Integer.toString(i)); traces.add(trace); } when(registryHelper.readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(TRACE_SUFFIX))).thenReturn(traces); ((VFSPipelineExecutorRegistry) pipelineExecutorRegistry).init(); verify(registryHelper, times(2)).ensureDirectory(PIPELINE_EXECUTOR_REGISTRY_PATH); verify(registryHelper, times(2)).readEntries(registryRoot, VFSRegistryHelper.BySuffixFilter.newFilter(TRACE_SUFFIX)); for (Object trace : traces) { PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(((PipelineExecutorTrace) trace).getTaskId()); assertNotNull(result); assertEquals(trace, result); } }