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); } }
@Override public void register(final PipelineExecutorTrace trace) { checkNotNull("trace", trace); final Path path = buildTracePath(trace.getTaskId()); try { registryHelper.storeEntry(path, trace); } catch (Exception e) { //uncommon error logger.error("Unexpected error was produced during trace marshalling/storing, trace: " + trace, e); throw new RuntimeException("Unexpected error was produced during trace marshalling/storing, trace: " + trace, e); } super.register(trace); }
@Test public void getExecutorTraceByRuntimeId() { RuntimeIdMock runtimeId = mock(RuntimeIdMock.class); when(runtimeId.getId()).thenReturn(RUNTIME_ID); PipelineExecutorTask task = mock(PipelineExecutorTask.class); when(task.getOutput()).thenReturn(runtimeId); when(trace.getTask()).thenReturn(task); pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(runtimeId); assertEquals(trace, result); }
@Test public void getExecutorTraceByRuntimeId() { RuntimeIdMock runtimeId = mock(RuntimeIdMock.class); when(runtimeId.getId()).thenReturn(RUNTIME_ID); PipelineExecutorTask task = mock(PipelineExecutorTask.class); when(task.getOutput()).thenReturn(runtimeId); when(trace.getTask()).thenReturn(task); pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(runtimeId); assertEquals(trace, result); }
@Test public void testGetExecutorTraces() { List<PipelineExecutorTrace> 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); } traces.forEach(trace -> pipelineExecutorRegistry.register(trace)); Collection<PipelineExecutorTrace> result = pipelineExecutorRegistry.getExecutorTraces(); assertEquals(traces.size(), result.size()); for (PipelineExecutorTrace trace : traces) { assertTrue(result.contains(trace)); } }
@Test public void testGetExecutorTraces() { List<PipelineExecutorTrace> 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); } traces.forEach(trace -> pipelineExecutorRegistry.register(trace)); Collection<PipelineExecutorTrace> result = pipelineExecutorRegistry.getExecutorTraces(); assertEquals(traces.size(), result.size()); for (PipelineExecutorTrace trace : traces) { assertTrue(result.contains(trace)); } }
@Test public void testRegisterWhenMarshallingErrors() throws Exception { prepareTargetPath(); expectedException.expectMessage("Unexpected error was produced during trace marshalling/storing, trace: " + trace); doThrow(new Exception("no matter the message here")) .when(registryHelper) .storeEntry(traceTargetPath, trace); pipelineExecutorRegistry.register(trace); }
@Test public void testRegisterWhenMarshallingErrors() throws Exception { prepareTargetPath(); expectedException.expectMessage("Unexpected error was produced during trace marshalling/storing, trace: " + trace); doThrow(new Exception("no matter the message here")) .when(registryHelper) .storeEntry(traceTargetPath, trace); pipelineExecutorRegistry.register(trace); }
@Test public void testRegister() { pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); }
@Test public void testRegister() { pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); }
@Test public void testGetExecutorTrace() { pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); }
@Test public void testGetExecutorTrace() { pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); }
@Test @Override public void testRegister() { prepareTargetPath(); pipelineExecutorRegistry.register(trace); try { verify(registryHelper, times(1)).storeEntry(traceTargetPath, trace); } catch (Exception e) { //need to catch this exception because parent class method don't throws exceptions, //but this will never happen in this scenario. fail(e.getMessage()); } PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); }
@Test @Override public void testRegister() { prepareTargetPath(); pipelineExecutorRegistry.register(trace); try { verify(registryHelper, times(1)).storeEntry(traceTargetPath, trace); } catch (Exception e) { //need to catch this exception because parent class method don't throws exceptions, //but this will never happen in this scenario. fail(e.getMessage()); } PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); }
@Test @Override public void testDeregister() { prepareTargetPath(); pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); pipelineExecutorRegistry.deregister(PIPELINE_EXECUTION_ID); verify(registryHelper, times(1)).deleteBatch(traceTargetPath); result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertNull(result); }
@Test @Override public void testDeregister() { prepareTargetPath(); pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); pipelineExecutorRegistry.deregister(PIPELINE_EXECUTION_ID); verify(registryHelper, times(1)).deleteBatch(traceTargetPath); result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertNull(result); }
@Test public void testDeregister() { pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); pipelineExecutorRegistry.deregister(trace.getTaskId()); result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertNull(result); }
@Test public void testDeregister() { pipelineExecutorRegistry.register(trace); PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertEquals(trace, result); pipelineExecutorRegistry.deregister(trace.getTaskId()); result = pipelineExecutorRegistry.getExecutorTrace(PIPELINE_EXECUTION_ID); assertNull(result); }