Search in sources :

Example 11 with NagiosCheckResult

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

the class GearmanResultServiceImplTest method testSaveAllResultsConnectionFailedCacheResults.

@Test
public void testSaveAllResultsConnectionFailedCacheResults() throws Exception {
    when(properties.isCacheEnabled()).thenReturn(true);
    TestSuite testSuite = new TestSuiteExampleBuilder().buildExample();
    when(checkResultBuilder.build(testSuite)).thenReturn(new NagiosCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
    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.tearDown(Optional.of(testSuite));
    // checks
    verify(gearmanCacheService).cacheResults(anyList());
    verify(gearmanCacheService).getCachedResults();
    verify(exceptionHandler).handleException(any(Exception.class));
    verify(testling).getGearmanClient();
    verify(testling).getGearmanConnection(host, port);
    verify(gearmanClient).addJobServer(connection);
    verify(gearmanClient).shutdown();
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) NagiosCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCheckResult) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) SakuliRuntimeException(org.sakuli.exceptions.SakuliRuntimeException) SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 12 with NagiosCheckResult

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

the class GearmanResultServiceImplTest method testSaveAllResultsConnectionFailed.

@Test
public void testSaveAllResultsConnectionFailed() throws Exception {
    when(gearmanClient.addJobServer(connection)).thenReturn(false);
    TestSuite testSuite = new TestSuiteExampleBuilder().buildExample();
    when(checkResultBuilder.build(testSuite)).thenReturn(new NagiosCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
    testling.tearDown(Optional.of(testSuite));
    // checks
    verify(gearmanCacheService, never()).cacheResults(anyList());
    verify(gearmanCacheService, never()).getCachedResults();
    verify(exceptionHandler).handleException(any(Exception.class));
    verify(testling).getGearmanClient();
    verify(testling).getGearmanConnection(host, port);
    verify(gearmanClient).addJobServer(connection);
    verify(gearmanClient).shutdown();
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) NagiosCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCheckResult) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) SakuliRuntimeException(org.sakuli.exceptions.SakuliRuntimeException) SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 13 with NagiosCheckResult

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

the class GearmanResultServiceImplTest method testCreateJobEncryptionEnabled.

@Test
public void testCreateJobEncryptionEnabled() throws Exception {
    when(properties.isEncryption()).thenReturn(true);
    final String secretKey = "abcdefghijklmnopqrstuvwxyz";
    when(properties.getSecretKey()).thenReturn(secretKey);
    GearmanJob gearmanJob = testling.creatJob(new NagiosCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
    assertEquals(Aes.decrypt(gearmanJob.getData(), secretKey), testResult);
}
Also used : NagiosCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCheckResult) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 14 with NagiosCheckResult

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

the class GearmanResultServiceImplTest method testSaveAllResultsWrongConnectionCacheResults.

@Test
public void testSaveAllResultsWrongConnectionCacheResults() throws Exception {
    final String host = "not-resolveable-host.de";
    when(properties.getServerHost()).thenReturn(host);
    when(properties.isCacheEnabled()).thenReturn(true);
    TestSuite testSuite = new TestSuiteExampleBuilder().buildExample();
    when(checkResultBuilder.build(testSuite)).thenReturn(new NagiosCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
    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(Exception.class), anyBoolean());
    testling.tearDown(Optional.of(testSuite));
    // checks
    verify(gearmanCacheService).cacheResults(anyList());
    verify(gearmanCacheService).getCachedResults();
    verify(exceptionHandler).handleException(any(SakuliForwarderRuntimeException.class));
    verify(testling).getGearmanClient();
    verify(testling).getGearmanConnection(host, port);
    verify(gearmanClient).addJobServer(connection);
    verify(gearmanClient).shutdown();
}
Also used : SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) TestSuite(org.sakuli.datamodel.TestSuite) NagiosCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCheckResult) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) SakuliRuntimeException(org.sakuli.exceptions.SakuliRuntimeException) SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 15 with NagiosCheckResult

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

the class GearmanCacheServiceTest method testCacheResultsEmptyAndNew.

@Test
public void testCacheResultsEmptyAndNew() throws Exception {
    when(testSuiteProperties.getTestSuiteFolder()).thenReturn(Paths.get("target"));
    when(gearmanProperties.getServerQueue()).thenReturn("check_results");
    List<NagiosCheckResult> results = new ArrayList<>();
    testling.cacheResults(results);
    Assert.assertEquals(testling.getCachedResults().size(), 0L);
    NagiosCheckResult newResult = checkResultBuilder.build(testSuite);
    results.add(newResult);
    testling.cacheResults(results);
    results = testling.getCachedResults();
    Assert.assertEquals(results.size(), 1L);
    Assert.assertEquals(results.get(0).getQueueName(), "check_results");
    Assert.assertEquals(results.get(0).getUuid(), newResult.getUuid());
    Assert.assertEquals(results.get(0).getPayload().trim(), newResult.getPayload().trim());
    NagiosCheckResult newResult2 = checkResultBuilder.build(testSuite);
    results.add(newResult2);
    testling.cacheResults(results);
    results = testling.getCachedResults();
    Assert.assertEquals(results.size(), 2L);
    Assert.assertEquals(results.get(0).getQueueName(), "check_results");
    Assert.assertEquals(results.get(0).getUuid(), newResult.getUuid());
    Assert.assertEquals(results.get(0).getPayload().trim(), newResult.getPayload().trim());
    Assert.assertEquals(results.get(1).getQueueName(), "check_results");
    Assert.assertEquals(results.get(1).getUuid(), newResult2.getUuid());
    Assert.assertEquals(results.get(1).getPayload().trim(), newResult2.getPayload().trim());
}
Also used : ArrayList(java.util.ArrayList) NagiosCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCheckResult) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Aggregations

NagiosCheckResult (org.sakuli.services.forwarder.gearman.model.NagiosCheckResult)15 BaseTest (org.sakuli.BaseTest)10 Test (org.testng.annotations.Test)10 SakuliForwarderRuntimeException (org.sakuli.exceptions.SakuliForwarderRuntimeException)7 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)6 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)6 TestSuite (org.sakuli.datamodel.TestSuite)6 SakuliRuntimeException (org.sakuli.exceptions.SakuliRuntimeException)6 ArrayList (java.util.ArrayList)4 SakuliForwarderCheckedException (org.sakuli.exceptions.SakuliForwarderCheckedException)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)2 SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 TreeMap (java.util.TreeMap)1 Future (java.util.concurrent.Future)1 PayLoadFields (org.sakuli.services.forwarder.gearman.model.PayLoadFields)1