use of com.walmartlabs.concord.plugins.s3.Result in project oracle-db-examples by oracle-samples.
the class MultiOperationTest method multiRowOperation.
/**
* Execute a query returning a single result.
*/
@Test
public void multiRowOperation() {
fail("TODO: Fix this test");
DataSourceFactory factory = DataSourceFactory.newFactory(FACTORY_NAME);
try (DataSource ds = factory.builder().url(URL).username(USER).password(PASSWORD).build();
Session session = ds.getSession(t -> fail("ERROR: " + t.getMessage()))) {
assertNotNull(session);
MultiOperation multiOp = session.multiOperation("select * from forum_user").onError(t -> {
fail(t.toString());
});
RowOperation rowOp = multiOp.<Integer>rowOperation();
multiOp.submit();
rowOp.collect(Collector.<Result.RowColumn, int[], Integer>of(() -> new int[1], (int[] a, Result.RowColumn r) -> {
a[0] = a[0] + r.at("sal").get(Integer.class);
}, (l, r) -> l, a -> (Integer) a[0])).onError(t -> {
fail(t.toString());
}).submit().getCompletionStage().thenAccept(n -> {
assertTrue(((long) n > 0));
}).toCompletableFuture().get(TestConfig.getTimeout().toMillis(), TimeUnit.MILLISECONDS);
} catch (Exception e) {
fail(e.getMessage());
e.printStackTrace();
}
}
use of com.walmartlabs.concord.plugins.s3.Result in project oracle-db-examples by oracle-samples.
the class RowPublisherOperationTest method rowSubscriber.
@Test
public void rowSubscriber() throws Exception {
System.out.println("rowSubscriber");
System.out.println("=============");
String sql = "select id, name from forum_user";
CompletableFuture<List<String>> result = new CompletableFuture<>();
CompletionStage<List<String>> cs;
Flow.Subscriber<Result.RowColumn> subscriber = getSubscriber(result, false);
try (Session session = getSession()) {
cs = session.<List<String>>rowPublisherOperation(sql).subscribe(subscriber, result).onError(e -> fail(e.getMessage())).submit().getCompletionStage();
}
cs.toCompletableFuture().get(getTimeout().toMillis(), TimeUnit.MILLISECONDS);
List<String> names = result.get(getTimeout().toMillis(), TimeUnit.MILLISECONDS);
;
assertNotNull(names);
assertFalse(names.isEmpty());
assertEquals(14, names.size());
}
use of com.walmartlabs.concord.plugins.s3.Result in project oracle-db-examples by oracle-samples.
the class SessionOperationGroupTest method testCollect.
/**
* Verify basic functionality of
* {@link Session#collect(java.util.stream.Collector)}
* @throws java.lang.Exception
*/
@Test
public void testCollect() throws Exception {
Submission<Object> seSubmission = null;
try (DataSource ds = TestConfig.getDataSource();
Session se = ds.builder().build()) {
Collector<Object, ?, Object> co = new ObjectCollector();
se.attachOperation().timeout(getTimeout()).submit();
se.collect(co).localOperation().onExecution(() -> 99).submit();
se.rowOperation("SELECT COUNT(*) FROM " + TABLE).collect(Collectors.summingInt(row -> row.at(1).get(Integer.class))).timeout(getTimeout()).submit();
se.endTransactionOperation(se.transactionCompletion()).submit();
seSubmission = se.submit();
}
// se.closeOperation().submit() // 5
assertNotNull(seSubmission);
@SuppressWarnings("unchecked") List<Integer> result = (List<Integer>) seSubmission.getCompletionStage().toCompletableFuture().get(getTimeout().toMillis(), TimeUnit.MILLISECONDS);
assertNotNull(result);
// Note the inline comments which count each submit (1, 2, 3...). This is
// the expected count of accumulated results.
assertEquals(5, result.size());
// Attach operation
assertNull(result.get(0));
// Local operation
assertEquals(99, result.get(1).intValue());
// Row operation
assertEquals(0, result.get(2).intValue());
assertEquals(TransactionOutcome.COMMIT, // Transaction operation
result.get(3));
// Close operation
assertNull(result.get(4));
}
use of com.walmartlabs.concord.plugins.s3.Result in project carbon-identity-framework by wso2.
the class TestJSONResponseWriter method testWriteWithAdvices.
@Test
public void testWriteWithAdvices() throws URISyntaxException {
List<AttributeAssignment> assignments = new ArrayList<>();
String content = "Error: Channel request is not WEB.";
URI type = new URI("http://www.w3.org/2001/XMLSchema#string");
URI attributeId = new URI("urn:oasis:names:tc:xacml:3.0:example:attribute:text");
AttributeAssignment attributeAssignment = new AttributeAssignment(attributeId, type, null, content, null);
assignments.add(attributeAssignment);
List<Advice> adviceResults = new ArrayList<>();
Advice adviceResult = new Advice(new URI("channel_ko"), assignments);
adviceResults.add(adviceResult);
List<String> codes = new ArrayList<>();
codes.add("urn:oasis:names:tc:xacml:1.0:status:ok");
AbstractResult abstractResult = new Result(1, new Status(codes), null, adviceResults, null);
ResponseCtx responseCtx = new ResponseCtx(abstractResult);
JSONResponseWriter jsonResponseWriter = new JSONResponseWriter();
try {
JsonObject jsonObject = jsonResponseWriter.write(responseCtx);
assertNotNull("Failed to build the XACML json response", jsonObject.toString());
assertFalse("Failed to build the XACML json response", jsonObject.entrySet().isEmpty());
for (Map.Entry<String, JsonElement> jsonElementEntry : jsonObject.entrySet()) {
if (jsonElementEntry.getKey().equals("Response")) {
JsonArray jsonArray = (JsonArray) jsonElementEntry.getValue();
assertEquals("Failed to build the XACML json response with correct evaluation", jsonArray.get(0).getAsJsonObject().get("Decision").getAsString(), "Deny");
}
}
} catch (ResponseWriteException e) {
assertNull("Failed to build the XACML json response", e);
}
}
use of com.walmartlabs.concord.plugins.s3.Result in project geotoolkit by Geomatys.
the class WPS2Process method checkResult.
/**
* A Function to ensure response object is success or failure. Otherwise, we request continually status until
* we reach a result.
*
* @param response The execute response given by service.
*/
private Result checkResult(Object response) throws IOException, JAXBException, InterruptedException, ProcessException {
if (response instanceof ExceptionResponse) {
final ExceptionResponse report = (ExceptionResponse) response;
throw new ProcessException("Exception when executing the process.", this, report.toException());
} else if (response instanceof StatusInfo) {
final StatusInfo statusInfo = (StatusInfo) response;
Status status = statusInfo.getStatus();
jobId = statusInfo.getJobID();
if (Status.SUCCEEDED.equals(status)) {
fireProgressing("WPS remote process has been successfully executed", 100f, false);
return null;
} else if (Status.FAILED.equals(status)) {
throw new ProcessException("Process failed", this);
} else if (Status.DISMISS.equals(status)) {
throw new DismissProcessException("WPS remote process has been canceled", this);
} else if (Status.ACCEPTED.equals(status)) {
// Initial status
fireProgressing("Process accepted: " + jobId, 0, false);
} else {
// Running
final Integer progress = statusInfo.getPercentCompleted();
// Not in the standard
String message = statusInfo.getMessage();
if (message == null || (message = message.trim()).isEmpty()) {
message = status.name();
}
fireProgressing(message, progress == null ? Float.NaN : progress, false);
}
// loop until we have an answer
Object tmpResponse;
// TODO : make timelapse configurable
int timeLapse = 3000;
// we tolerate a few unmarshalling or IO errors, the servers behave differentely
// and may not offer the result file right from the start
int failCount = 0;
while (true) {
stopIfDismissed();
synchronized (this) {
wait(timeLapse);
}
try {
tmpResponse = getStatus();
failCount = 0;
} catch (UnmarshalException | IOException ex) {
if (failCount < 5 && !isDimissed()) {
failCount++;
continue;
} else if (isDimissed()) {
throw new DismissProcessException("WPS remote process has been canceled", this);
} else {
// happenning so we consider the process failed
throw ex;
}
}
if (tmpResponse instanceof StatusInfo) {
final StatusInfo statInfo = (StatusInfo) tmpResponse;
status = statInfo.getStatus();
if (Status.SUCCEEDED.equals(status)) {
fireProgressing("WPS remote process has been successfully executed", 100f, false);
return null;
} else if (Status.FAILED.equals(status)) {
throw new ProcessException("Process failed", this);
} else if (Status.DISMISS.equals(status)) {
throw new DismissProcessException("WPS remote process has been canceled", this);
}
// Not in the standard
String message = statusInfo.getMessage();
if (message == null || (message = message.trim()).isEmpty()) {
message = status.name();
}
final Integer percentCompleted = statInfo.getPercentCompleted();
if (!Objects.equals(message, lastMessage) || !Objects.equals(percentCompleted, lastProgress)) {
lastMessage = message;
lastProgress = percentCompleted;
fireProgressing(lastMessage, lastProgress, false);
}
} else if (tmpResponse instanceof ExceptionResponse) {
final ExceptionResponse report = (ExceptionResponse) tmpResponse;
throw new ProcessException("Exception when executing the process.", this, report.toException());
}
}
} else if (response instanceof Result) {
final Result result = checkLegacyResult((Result) response);
if (result.getJobID() != null) {
jobId = result.getJobID();
}
return result;
} else {
throw new ProcessException("Unexpected response " + response, this);
}
}
Aggregations