use of com.mercedesbenz.sechub.adapter.AdapterException in project sechub by mercedes-benz.
the class CheckmarxProductExecutorMockTest method when_adapter_throws_first_time_adapter_exception_with_exceed_a_retry_is_done.
@Test
public void when_adapter_throws_first_time_adapter_exception_with_exceed_a_retry_is_done() throws Exception {
/* prepare */
SecHubExecutionContext context = createExecutionContextForPseudoCodeScan();
ProductExecutorCallback callback = mock(ProductExecutorCallback.class);
ProductExecutorConfigSetup setup = createCheckmarxSetupWithAllMandotoryPartsSet();
ProductExecutorConfig executorConfig = new ProductExecutorConfig(ProductIdentifier.CHECKMARX, 1, setup);
ProductExecutorContext executorContext = mock(ProductExecutorContext.class);
when(executorContext.getCallback()).thenReturn(callback);
when(executorContext.getExecutorConfig()).thenReturn(executorConfig);
ProductResult currentResult = new ProductResult(JOB_UUID, PROJECT_EXAMPLE, executorConfig, "pseudo-result");
when(executorContext.getCurrentProductResult()).thenReturn(currentResult);
/* @formatter:off */
when(checkmarxAdapter.start(any(), any())).thenThrow(// first fails
new AdapterException(new AdapterLogId("1", "traceId"), "bla bla - Changes exceeded the threshold limit - bla bla")).thenReturn(// second: access
"result2");
/* @formatter:on */
/* execute */
executorToTest.execute(context, executorContext);
/* test */
// the adapter must be called twice
verify(checkmarxAdapter, times(2)).start(any(), any());
}
use of com.mercedesbenz.sechub.adapter.AdapterException in project sechub by mercedes-benz.
the class CheckmarxProductExecutorMockTest method when_adapter_throws_two_time_adapter_exception_with_exceed_a_retry_is_done_only_one_time.
@Test
public void when_adapter_throws_two_time_adapter_exception_with_exceed_a_retry_is_done_only_one_time() throws Exception {
/* prepare */
SecHubExecutionContext context = createExecutionContextForPseudoCodeScan();
ProductExecutorCallback callback = mock(ProductExecutorCallback.class);
ProductExecutorConfigSetup setup = createCheckmarxSetupWithAllMandotoryPartsSet();
ProductExecutorConfig executorConfig = new ProductExecutorConfig(ProductIdentifier.CHECKMARX, 1, setup);
ProductExecutorContext executorContext = mock(ProductExecutorContext.class);
when(executorContext.getCallback()).thenReturn(callback);
when(executorContext.getExecutorConfig()).thenReturn(executorConfig);
ProductResult currentResult = new ProductResult(JOB_UUID, PROJECT_EXAMPLE, executorConfig, "pseudo-result");
when(executorContext.getCurrentProductResult()).thenReturn(currentResult);
/* @formatter:off */
when(checkmarxAdapter.start(any(), any())).thenThrow(// first fails
new AdapterException(new AdapterLogId("1", "traceId"), "bla bla - Changes exceeded the threshold limit - bla bla")).thenThrow(// second fails
new AdapterException(new AdapterLogId("2", "traceId"), "bla bla - Changes exceeded the threshold limit - bla bla")).thenReturn(// third: would be access but should not happen! resilience shall here only work one time!
"result2");
/* @formatter:on */
SecHubExecutionException expected = null;
/* execute */
try {
executorToTest.execute(context, executorContext);
} catch (SecHubExecutionException e) {
expected = e;
}
/* test */
assertNotNull("No SecHubExecutionException happened, but must!", expected);
// the adapter must be called twice - first errr, than one retry, third error
verify(checkmarxAdapter, times(2)).start(any(), any());
// means no retry again
Throwable cause = expected.getCause();
String message = cause.getMessage();
assertTrue(message.contains("Changes exceeded the threshold limit"));
}
use of com.mercedesbenz.sechub.adapter.AdapterException in project sechub by mercedes-benz.
the class AdapterExceptionTest method throwAsAdapterException_rethrows_adapter_exception_when_exception_is_adapter_exception.
@Test
public void throwAsAdapterException_rethrows_adapter_exception_when_exception_is_adapter_exception() throws Exception {
/* prepare */
AdapterException cause = new AdapterException(new AdapterLogId("y", null), "originMessage");
/* test */
expected.expect(AdapterException.class);
expected.expectMessage("y:originMessage");
/* execute */
throwAsAdapterException(new AdapterLogId("z", null), "otherMessage", cause);
}
use of com.mercedesbenz.sechub.adapter.AdapterException in project sechub by mercedes-benz.
the class PDSAdapterV1 method waitForJobDone.
private void waitForJobDone(PDSContext context) throws AdapterException {
PDSAdapterConfig config = context.getConfig();
PDSAdapterConfigData data = config.getPDSAdapterConfigData();
UUID secHubJobUUID = data.getSecHubJobUUID();
UUID pdsJobUUID = context.getPdsJobUUID();
int count = 0;
boolean jobEnded = false;
PDSJobStatus jobstatus = null;
long started = getCurrentTimeMilliseconds();
int timeToWaitForNextCheckOperationInMilliseconds = config.getTimeToWaitForNextCheckOperationInMilliseconds();
LOG.info("Start waiting for PDS-job:{} to be done. Related SecHub-Job is:{} . Will check every {} ms. Adapter will wait maximum {} ms before timeout.", pdsJobUUID, secHubJobUUID, timeToWaitForNextCheckOperationInMilliseconds, config.getTimeOutInMilliseconds());
while (!jobEnded && isNotTimeout(config, started)) {
count++;
LOG.debug("Fetch job status for PDS-job:{}. Elapsed time for {} retries:{} ms", pdsJobUUID, count, calculateElapsedTime(started));
/* see PDSJobStatusState.java */
jobstatus = getJobStatus(context);
PDSAdapterJobStatusState state = jobstatus.state;
switch(state) {
case DONE:
jobEnded = true;
break;
case FAILED:
throw asAdapterException("PDS job execution failed", config);
case CANCELED:
throw asAdapterCanceledByUserException(config);
default:
}
if (jobEnded) {
// break while...
break;
}
assertNotInterrupted();
try {
Thread.sleep(timeToWaitForNextCheckOperationInMilliseconds);
} catch (InterruptedException e) {
throw new AdapterException(getAdapterLogId(null), "Execution thread was interrupted");
}
}
if (!jobEnded) {
long elapsedTimeInMilliseconds = calculateElapsedTime(started);
throw new IllegalStateException("Even after " + count + " retries, every waiting " + timeToWaitForNextCheckOperationInMilliseconds + " ms, no job report state acceppted as END was found.!\nElapsed time were" + elapsedTimeInMilliseconds + " ms.\nLAST fetched jobstatus for " + secHubJobUUID + ", PDS job uuid: " + pdsJobUUID + " was:\n" + jobstatus);
}
}
use of com.mercedesbenz.sechub.adapter.AdapterException in project sechub by mercedes-benz.
the class AssertProject method hasMetaData.
public AssertProject hasMetaData(Map<String, String> expectedMap) {
String content = fetchProjectDetails();
Map<String, String> found = new HashMap<>();
JsonNode metaDataNode;
try {
metaDataNode = JSONAdapterSupport.FOR_UNKNOWN_ADAPTER.fetch("metaData", content).asNode();
metaDataNode.fieldNames().forEachRemaining(key -> {
JsonNode element = metaDataNode.get(key);
if (element.isTextual()) {
String value = element.textValue();
found.put(key, value);
}
});
} catch (AdapterException e) {
e.printStackTrace();
fail("adapter jso failure:" + e.getMessage());
}
assertEquals(expectedMap, found);
return this;
}
Aggregations