Search in sources :

Example 6 with NagiosCachedCheckResult

use of org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult in project sakuli by ConSol.

the class GearmanResultServiceImplTest method testCreateJobEncryptionEnabled.

@Test
public void testCreateJobEncryptionEnabled() throws Exception {
    when(properties.getServiceType()).thenReturn("passive");
    final String queueName = "check_results";
    when(properties.getServerQueue()).thenReturn(queueName);
    final String host = "99.99.99.20";
    when(properties.getServerHost()).thenReturn(host);
    final int port = 4730;
    when(properties.getServerPort()).thenReturn(port);
    when(properties.getNagiosHost()).thenReturn("win7sakuli");
    when(properties.isEncryption()).thenReturn(true);
    final String secretKey = "abcdefghijklmnopqrstuvwxyz";
    when(properties.getSecretKey()).thenReturn(secretKey);
    GearmanJob gearmanJob = testling.creatJob(new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
    assertEquals(Aes.decrypt(gearmanJob.getData(), secretKey), testResult);
}
Also used : NagiosCachedCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 7 with NagiosCachedCheckResult

use of org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult in project sakuli by ConSol.

the class GearmanResultServiceImplTest method testSaveAllResultsWrongConnectionCacheResults.

@Test
public void testSaveAllResultsWrongConnectionCacheResults() throws Exception {
    when(properties.getServiceType()).thenReturn("passive");
    final String queueName = "check_results";
    when(properties.getServerQueue()).thenReturn(queueName);
    final String host = "not-resolveable-host.de";
    when(properties.getServerHost()).thenReturn(host);
    final int port = 4730;
    when(properties.getServerPort()).thenReturn(port);
    when(properties.getNagiosHost()).thenReturn("win7sakuli");
    when(properties.isCacheEnabled()).thenReturn(true);
    when(checkResultBuilder.build()).thenReturn(new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
    GearmanClient gearmanClient = mock(GearmanClientImpl.class);
    doReturn(gearmanClient).when(testling).getGearmanClient();
    GearmanJobServerConnection connection = mock(GearmanJobServerConnection.class);
    doReturn(connection).when(testling).getGearmanConnection(host, port);
    when(gearmanClient.addJobServer(connection)).thenThrow(new UnresolvedAddressException());
    when(gearmanCacheService.getCachedResults()).thenReturn(Collections.emptyList());
    doAnswer(invocationOnMock -> {
        assertEquals(((List) invocationOnMock.getArguments()[0]).size(), 1L);
        return null;
    }).when(gearmanCacheService).cacheResults(anyList());
    doAnswer(invocationOnMock -> {
        Exception exception = (Exception) invocationOnMock.getArguments()[0];
        assertRegExMatch(exception.getMessage(), "Could not transfer Sakuli results to the Gearman server.*");
        assertEquals(exception.getSuppressed()[0].getClass(), UnresolvedAddressException.class);
        return null;
    }).when(exceptionHandler).handleException(any(Throwable.class), anyBoolean());
    testling.saveAllResults();
    //checks
    verify(gearmanCacheService).cacheResults(anyList());
    verify(gearmanCacheService).getCachedResults();
    verify(exceptionHandler).handleException(any(SakuliForwarderException.class), anyBoolean());
    verify(testling).getGearmanClient();
    verify(testling).getGearmanConnection(host, port);
    verify(gearmanClient).addJobServer(connection);
    verify(gearmanClient).shutdown();
}
Also used : GearmanJobServerConnection(org.gearman.common.GearmanJobServerConnection) NagiosCachedCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult) SakuliForwarderException(org.sakuli.exceptions.SakuliForwarderException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) SakuliForwarderException(org.sakuli.exceptions.SakuliForwarderException) SakuliRuntimeException(org.sakuli.exceptions.SakuliRuntimeException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) SakuliActionException(org.sakuli.exceptions.SakuliActionException) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 8 with NagiosCachedCheckResult

use of org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult in project sakuli by ConSol.

the class GearmanResultServiceImplTest method testSaveAllResultsConnectionFailedCacheResults.

@Test
public void testSaveAllResultsConnectionFailedCacheResults() throws Exception {
    when(properties.getServiceType()).thenReturn("passive");
    final String queueName = "check_results";
    when(properties.getServerQueue()).thenReturn(queueName);
    final String host = "99.99.99.20";
    when(properties.getServerHost()).thenReturn(host);
    final int port = 4730;
    when(properties.getServerPort()).thenReturn(port);
    when(properties.getNagiosHost()).thenReturn("win7sakuli");
    when(properties.isCacheEnabled()).thenReturn(true);
    when(checkResultBuilder.build()).thenReturn(new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
    GearmanClient gearmanClient = mock(GearmanClientImpl.class);
    doReturn(gearmanClient).when(testling).getGearmanClient();
    GearmanJobServerConnection connection = mock(GearmanJobServerConnection.class);
    doReturn(connection).when(testling).getGearmanConnection(host, port);
    when(gearmanClient.addJobServer(connection)).thenReturn(false);
    when(gearmanCacheService.getCachedResults()).thenReturn(Collections.emptyList());
    doAnswer(invocationOnMock -> {
        assertEquals(((List) invocationOnMock.getArguments()[0]).size(), 1L);
        return null;
    }).when(gearmanCacheService).cacheResults(anyList());
    testling.saveAllResults();
    //checks
    verify(gearmanCacheService).cacheResults(anyList());
    verify(gearmanCacheService).getCachedResults();
    verify(exceptionHandler).handleException(any(Throwable.class), eq(true));
    verify(testling).getGearmanClient();
    verify(testling).getGearmanConnection(host, port);
    verify(gearmanClient).addJobServer(connection);
    verify(gearmanClient).shutdown();
}
Also used : GearmanJobServerConnection(org.gearman.common.GearmanJobServerConnection) NagiosCachedCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 9 with NagiosCachedCheckResult

use of org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult in project sakuli by ConSol.

the class GearmanResultServiceImplTest method testSaveAllResultsConnectionFailed.

@Test
public void testSaveAllResultsConnectionFailed() throws Exception {
    when(properties.getServiceType()).thenReturn("passive");
    final String queueName = "check_results";
    when(properties.getServerQueue()).thenReturn(queueName);
    final String host = "99.99.99.20";
    when(properties.getServerHost()).thenReturn(host);
    final int port = 4730;
    when(properties.getServerPort()).thenReturn(port);
    when(properties.getNagiosHost()).thenReturn("win7sakuli");
    when(checkResultBuilder.build()).thenReturn(new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
    GearmanClient gearmanClient = mock(GearmanClientImpl.class);
    doReturn(gearmanClient).when(testling).getGearmanClient();
    GearmanJobServerConnection connection = mock(GearmanJobServerConnection.class);
    doReturn(connection).when(testling).getGearmanConnection(host, port);
    when(gearmanClient.addJobServer(connection)).thenReturn(false);
    testling.saveAllResults();
    //checks
    verify(gearmanCacheService, never()).cacheResults(anyList());
    verify(gearmanCacheService, never()).getCachedResults();
    verify(exceptionHandler).handleException(any(Throwable.class), eq(true));
    verify(testling).getGearmanClient();
    verify(testling).getGearmanConnection(host, port);
    verify(gearmanClient).addJobServer(connection);
    verify(gearmanClient).shutdown();
}
Also used : GearmanJobServerConnection(org.gearman.common.GearmanJobServerConnection) NagiosCachedCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Aggregations

NagiosCachedCheckResult (org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult)9 BaseTest (org.sakuli.BaseTest)8 Test (org.testng.annotations.Test)8 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)6 NagiosCheckResult (org.sakuli.services.forwarder.gearman.model.NagiosCheckResult)4 SakuliActionException (org.sakuli.exceptions.SakuliActionException)2 SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)2 SakuliRuntimeException (org.sakuli.exceptions.SakuliRuntimeException)2 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)1 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)1 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)1 TestSuite (org.sakuli.datamodel.TestSuite)1