use of com.aws.greengrass.provisioning.exceptions.RetryableProvisioningException in project aws-greengrass-nucleus by aws-greengrass.
the class KernelLifecycleTest method GIVEN_kernel_WHEN_launch_with_provisioning_plugin_AND_plugin_methods_throw_retryable_Exception_THEN_plugin_retries_successfully.
@SuppressWarnings("PMD.CloseResource")
@Test
void GIVEN_kernel_WHEN_launch_with_provisioning_plugin_AND_plugin_methods_throw_retryable_Exception_THEN_plugin_retries_successfully(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, RetryableProvisioningException.class);
mockProvisioning();
doAnswer(new Answer() {
int count = 0;
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
count++;
if (count == 1) {
throw new RetryableProvisioningException("Retryable error in provisioning");
} else {
return createMockProvisioningConforguration();
}
}
}).when(mockProvisioningPlugin).updateIdentityConfiguration(any());
EZPlugins pluginMock = mock(EZPlugins.class);
when(mockContext.get(EZPlugins.class)).thenReturn(pluginMock);
doAnswer((i) -> {
ImplementingClassMatchProcessor func = i.getArgument(1);
func.processMatch(mockPluginClass);
return null;
}).when(pluginMock).implementing(eq(DeviceIdentityInterface.class), any());
kernelLifecycle.launch();
verify(mockProvisioningPlugin, timeout(2000).times(2)).updateIdentityConfiguration(any(ProvisionContext.class));
verify(mockProvisioningConfigUpdateHelper, timeout(1000).times(1)).updateNucleusConfiguration(any(NucleusConfiguration.class), eq(UpdateBehaviorTree.UpdateBehavior.MERGE));
verify(mockProvisioningConfigUpdateHelper, times(1)).updateSystemConfiguration(any(SystemConfiguration.class), eq(UpdateBehaviorTree.UpdateBehavior.MERGE));
}
use of com.aws.greengrass.provisioning.exceptions.RetryableProvisioningException in project aws-greengrass-nucleus by aws-greengrass.
the class KernelLifecycleTest method GIVEN_kernel_WHEN_launch_with_provisioning_plugin_AND_plugin_methods_throw_retryable_Exception_THEN_plugin_fails_after_max_attempt.
@SuppressWarnings("PMD.CloseResource")
@Test
void GIVEN_kernel_WHEN_launch_with_provisioning_plugin_AND_plugin_methods_throw_retryable_Exception_THEN_plugin_fails_after_max_attempt(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, RetryableProvisioningException.class);
mockProvisioning();
when(mockProvisioningPlugin.updateIdentityConfiguration(any())).thenThrow(new RetryableProvisioningException("Retryable error"));
EZPlugins pluginMock = mock(EZPlugins.class);
when(mockContext.get(EZPlugins.class)).thenReturn(pluginMock);
doAnswer((i) -> {
ImplementingClassMatchProcessor func = i.getArgument(1);
func.processMatch(mockPluginClass);
return null;
}).when(pluginMock).implementing(eq(DeviceIdentityInterface.class), any());
kernelLifecycle.launch();
// wait for retries
Thread.sleep(7000);
// verification with timeout seems to fail prematurely instead of waiting for the timeout period
verify(mockProvisioningPlugin, times(3)).updateIdentityConfiguration(any(ProvisionContext.class));
verify(mockProvisioningConfigUpdateHelper, times(0)).updateNucleusConfiguration(any(NucleusConfiguration.class), eq(UpdateBehaviorTree.UpdateBehavior.MERGE));
verify(mockProvisioningConfigUpdateHelper, times(0)).updateSystemConfiguration(any(SystemConfiguration.class), eq(UpdateBehaviorTree.UpdateBehavior.MERGE));
}
Aggregations