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();
}
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();
}
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);
}
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();
}
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());
}
Aggregations