use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class KernelTest method GIVEN_kernel_WHEN_locate_finds_definition_in_config_THEN_create_GenericExternalService.
@Test
void GIVEN_kernel_WHEN_locate_finds_definition_in_config_THEN_create_GenericExternalService() throws Exception {
Configuration config = kernel.getConfig();
config.lookupTopics(GreengrassService.SERVICES_NAMESPACE_TOPIC, "1", GreengrassService.SERVICE_LIFECYCLE_NAMESPACE_TOPIC);
GreengrassService main = kernel.locate("1");
assertEquals("1", main.getName());
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class KernelTest method GIVEN_kernel_WHEN_locate_finds_classname_but_not_class_THEN_throws_ServiceLoadException.
@Test
void GIVEN_kernel_WHEN_locate_finds_classname_but_not_class_THEN_throws_ServiceLoadException() {
String badClassName = TestClass.class.getName() + "lkajsdklajglsdj";
Configuration config = kernel.getConfig();
config.lookup(GreengrassService.SERVICES_NAMESPACE_TOPIC, "2", "class").withValue(badClassName);
ServiceLoadException ex = assertThrows(ServiceLoadException.class, () -> kernel.locate("2"));
assertEquals("Can't load service class from " + badClassName, ex.getMessage());
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleTest method GIVEN_service_starting_WHEN_dependency_errored_THEN_service_restarted.
@Test
void GIVEN_service_starting_WHEN_dependency_errored_THEN_service_restarted() throws Exception {
Topics serviceRoot = new Configuration(context).getRoot().createInteriorChild(GreengrassService.SERVICES_NAMESPACE_TOPIC);
Topics testServiceTopics = serviceRoot.createInteriorChild("testService");
TestService testService = new TestService(testServiceTopics);
Topics dependencyServiceTopics = serviceRoot.createInteriorChild("dependencyService");
TestService dependencyService = new TestService(dependencyServiceTopics);
testService.addOrUpdateDependency(dependencyService, DependencyType.HARD, false);
CountDownLatch serviceStarted = new CountDownLatch(1);
testService.setStartupRunnable(() -> {
try {
serviceStarted.countDown();
Thread.sleep(10_000);
} catch (InterruptedException ie) {
return;
}
});
dependencyService.setStartupRunnable(() -> dependencyService.reportState(State.RUNNING));
// init lifecycle
testService.postInject();
testService.requestStart();
dependencyService.postInject();
dependencyService.requestStart();
// GIVEN service in state STARTING
assertTrue(serviceStarted.await(1500, TimeUnit.MILLISECONDS));
assertEquals(State.STARTING, testService.getState());
CountDownLatch serviceRestarted = new CountDownLatch(2);
context.addGlobalStateChangeListener((service, oldState, newState) -> {
if (!"testService".equals(service.getName())) {
return;
}
if (State.STARTING.equals(oldState) && State.STOPPING.equals(newState) && serviceRestarted.getCount() == 2) {
serviceRestarted.countDown();
return;
}
if (State.INSTALLED.equals(oldState) && State.STARTING.equals(newState) && serviceRestarted.getCount() == 1) {
serviceRestarted.countDown();
return;
}
});
// WHEN dependency errored
dependencyService.reportState(State.ERRORED);
// THEN
assertTrue(serviceRestarted.await(500, TimeUnit.MILLISECONDS));
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleTest method GIVEN_service_running_WHEN_service_broken_THEN_service_is_stopped.
@Test
void GIVEN_service_running_WHEN_service_broken_THEN_service_is_stopped() throws Exception {
Topics serviceRoot = new Configuration(context).getRoot().createInteriorChild(GreengrassService.SERVICES_NAMESPACE_TOPIC);
Topics testServiceTopics = serviceRoot.createInteriorChild("testService");
TestService testService = new TestService(testServiceTopics);
AtomicInteger serviceStartedCount = new AtomicInteger();
AtomicInteger serviceStoppedCount = new AtomicInteger();
AtomicInteger serviceInterruptedCount = new AtomicInteger();
testService.setStartupRunnable(() -> {
try {
serviceStartedCount.incrementAndGet();
testService.reportState(State.ERRORED);
Thread.sleep(2000);
} catch (InterruptedException e) {
serviceInterruptedCount.incrementAndGet();
}
});
testService.setShutdownRunnable(() -> serviceStoppedCount.incrementAndGet());
// init lifecycle
testService.postInject();
testService.requestStart();
assertThat(testService::getState, eventuallyEval(is(State.BROKEN)));
assertThat(serviceStoppedCount::get, eventuallyEval(is(serviceStartedCount.get())));
assertThat(serviceInterruptedCount::get, eventuallyEval(is(serviceStartedCount.get())));
// assert that service remains in BROKEN state
assertEquals(State.BROKEN, testService.getState());
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class KernelUpdateDeploymentTaskTest method beforeEach.
@BeforeEach
void beforeEach() throws Exception {
lenient().doReturn(kernelAlternatives).when(context).get(KernelAlternatives.class);
lenient().doReturn(deploymentDirectoryManager).when(context).get(DeploymentDirectoryManager.class);
lenient().doReturn(context).when(kernel).getContext();
lenient().doReturn("A").when(greengrassService).getName();
lenient().doReturn(mainService).when(kernel).getMain();
lenient().doReturn(true).when(greengrassService).shouldAutoStart();
lenient().doReturn(Arrays.asList(greengrassService)).when(kernel).orderedDependencies();
lenient().doNothing().when(componentManager).cleanupStaleVersions();
Topic topic = mock(Topic.class);
lenient().doReturn(1L).when(topic).getModtime();
Configuration configuration = mock(Configuration.class);
lenient().doReturn(topic).when(configuration).lookup(any());
lenient().doReturn(configuration).when(kernel).getConfig();
DeploymentDocument document = mock(DeploymentDocument.class);
doReturn("mockId").when(document).getDeploymentId();
doReturn(document).when(deployment).getDeploymentDocumentObj();
task = new KernelUpdateDeploymentTask(kernel, logger, deployment, componentManager);
}
Aggregations