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); } }
@Override public void registerRuntime(final Runtime runtime) { checkNotNull("runtime", runtime); final Path path = buildRuntimePath(runtime.getId()); try { registryHelper.storeEntry(path, runtime); } catch (Exception e) { //uncommon error logger.error("Unexpected error was produced during runtime marshalling/storing, runtime: " + runtime, e); throw new RuntimeException("Unexpected error was produced during runtime marshalling/storing, runtime: " + runtime, e); } super.registerRuntime(runtime); }
@Test public void testRegisterRuntime() { runtimeRegistry.registerRuntime(runtime); verifyRuntimeIsRegistered(runtime); }
@Test public void testRegisterRuntime() { runtimeRegistry.registerRuntime(runtime); verifyRuntimeIsRegistered(runtime); }
@Test public void testRegisterRuntimeWhenMarshallingErrors() throws Exception { prepareRuntimeTargetPath(); expectedException.expectMessage("Unexpected error was produced during runtime marshalling/storing, runtime: " + runtime); doThrow(new Exception("no matter the message here")) .when(registryHelper) .storeEntry(runtimeTargetPath, runtime); runtimeRegistry.registerRuntime(runtime); }
@Test public void testRegisterRuntimeWhenMarshallingErrors() throws Exception { prepareRuntimeTargetPath(); expectedException.expectMessage("Unexpected error was produced during runtime marshalling/storing, runtime: " + runtime); doThrow(new Exception("no matter the message here")) .when(registryHelper) .storeEntry(runtimeTargetPath, runtime); runtimeRegistry.registerRuntime(runtime); }
@Test public void testDeregisterRuntime() { String id = runtime.getId(); RuntimeId runtimeId = mock(RuntimeId.class); when(runtimeId.getId()).thenReturn(id); runtimeRegistry.registerRuntime(runtime); verifyRuntimeIsRegistered(runtime); runtimeRegistry.deregisterRuntime(runtimeId); verifyRuntimeIsNotRegistered(runtime); }
@Test public void testDeregisterRuntime() { String id = runtime.getId(); RuntimeId runtimeId = mock(RuntimeId.class); when(runtimeId.getId()).thenReturn(id); runtimeRegistry.registerRuntime(runtime); verifyRuntimeIsRegistered(runtime); runtimeRegistry.deregisterRuntime(runtimeId); verifyRuntimeIsNotRegistered(runtime); }
@Test @Override public void testRegisterRuntime() { prepareRuntimeTargetPath(); runtimeRegistry.registerRuntime(runtime); try { verify(registryHelper, times(1)).storeEntry(runtimeTargetPath, runtime); } 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()); } verifyRuntimeIsRegistered(runtime); }
@Test @Override public void testRegisterRuntime() { prepareRuntimeTargetPath(); runtimeRegistry.registerRuntime(runtime); try { verify(registryHelper, times(1)).storeEntry(runtimeTargetPath, runtime); } 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()); } verifyRuntimeIsRegistered(runtime); }
@Test @Override public void testDeregisterRuntime() { prepareRuntimeTargetPath(); runtimeRegistry.registerRuntime(runtime); verifyRuntimeIsRegistered(runtime); runtimeRegistry.deregisterRuntime(runtime); verify(registryHelper, times(1)).deleteBatch(runtimeTargetPath); verifyRuntimeIsNotRegistered(runtime); }
@Test @Override public void testDeregisterRuntime() { prepareRuntimeTargetPath(); runtimeRegistry.registerRuntime(runtime); verifyRuntimeIsRegistered(runtime); runtimeRegistry.deregisterRuntime(runtime); verify(registryHelper, times(1)).deleteBatch(runtimeTargetPath); verifyRuntimeIsNotRegistered(runtime); }
@Test public void testGetRuntimes() { List<Runtime> result = runtimeRegistry.getRuntimes(0, 1000, RuntimeRegistry.RUNTIME_ID_SORT, true); assertTrue(result.isEmpty()); List<Runtime> runtimes = mockRuntimeList(providerId, "", ELEMENTS_COUNT); runtimes.forEach(runtime -> runtimeRegistry.registerRuntime(runtime)); result = runtimeRegistry.getRuntimes(0, 1000, RuntimeRegistry.RUNTIME_ID_SORT, true); for (Runtime runtime : runtimes) { assertTrue(result.contains(runtime)); } }
@Test public void testGetRuntimeById() { String id = runtime.getId(); runtimeRegistry.registerRuntime(runtime); Runtime result = runtimeRegistry.getRuntimeById(id); assertEquals(runtime, result); }
@Test public void testGetRuntimes() { List<Runtime> result = runtimeRegistry.getRuntimes(0, 1000, RuntimeRegistry.RUNTIME_ID_SORT, true); assertTrue(result.isEmpty()); List<Runtime> runtimes = mockRuntimeList(providerId, "", ELEMENTS_COUNT); runtimes.forEach(runtime -> runtimeRegistry.registerRuntime(runtime)); result = runtimeRegistry.getRuntimes(0, 1000, RuntimeRegistry.RUNTIME_ID_SORT, true); for (Runtime runtime : runtimes) { assertTrue(result.contains(runtime)); } }
@Test public void testGetRuntimeById() { String id = runtime.getId(); runtimeRegistry.registerRuntime(runtime); Runtime result = runtimeRegistry.getRuntimeById(id); assertEquals(runtime, result); }