Search in sources :

Example 1 with RetryableProvisioningException

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));
}
Also used : DeviceIdentityInterface(com.aws.greengrass.provisioning.DeviceIdentityInterface) RetryableProvisioningException(com.aws.greengrass.provisioning.exceptions.RetryableProvisioningException) NucleusConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration.NucleusConfiguration) SystemConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration.SystemConfiguration) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) EZPlugins(com.aws.greengrass.dependency.EZPlugins) ProvisionContext(com.aws.greengrass.provisioning.ProvisionContext) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImplementingClassMatchProcessor(io.github.lukehutch.fastclasspathscanner.matchprocessor.ImplementingClassMatchProcessor) Test(org.junit.jupiter.api.Test)

Example 2 with RetryableProvisioningException

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));
}
Also used : EZPlugins(com.aws.greengrass.dependency.EZPlugins) DeviceIdentityInterface(com.aws.greengrass.provisioning.DeviceIdentityInterface) ProvisionContext(com.aws.greengrass.provisioning.ProvisionContext) RetryableProvisioningException(com.aws.greengrass.provisioning.exceptions.RetryableProvisioningException) NucleusConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration.NucleusConfiguration) ImplementingClassMatchProcessor(io.github.lukehutch.fastclasspathscanner.matchprocessor.ImplementingClassMatchProcessor) SystemConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration.SystemConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

EZPlugins (com.aws.greengrass.dependency.EZPlugins)2 DeviceIdentityInterface (com.aws.greengrass.provisioning.DeviceIdentityInterface)2 NucleusConfiguration (com.aws.greengrass.provisioning.ProvisionConfiguration.NucleusConfiguration)2 SystemConfiguration (com.aws.greengrass.provisioning.ProvisionConfiguration.SystemConfiguration)2 ProvisionContext (com.aws.greengrass.provisioning.ProvisionContext)2 RetryableProvisioningException (com.aws.greengrass.provisioning.exceptions.RetryableProvisioningException)2 ImplementingClassMatchProcessor (io.github.lukehutch.fastclasspathscanner.matchprocessor.ImplementingClassMatchProcessor)2 Test (org.junit.jupiter.api.Test)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1