Search in sources :

Example 41 with Result

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();
    }
}
Also used : DataSourceFactory(jdk.incubator.sql2.DataSourceFactory) BeforeClass(org.junit.BeforeClass) RowOperation(jdk.incubator.sql2.RowOperation) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) SqlException(jdk.incubator.sql2.SqlException) OperationGroup(jdk.incubator.sql2.OperationGroup) Flow(java.util.concurrent.Flow) BiConsumer(java.util.function.BiConsumer) Collector(java.util.stream.Collector) Session(jdk.incubator.sql2.Session) AfterClass(org.junit.AfterClass) Properties(java.util.Properties) JDBC_CONNECTION_PROPERTIES(com.oracle.adbaoverjdbc.JdbcConnectionProperties.JDBC_CONNECTION_PROPERTIES) AdbaType(jdk.incubator.sql2.AdbaType) Test(org.junit.Test) RowPublisherOperation(jdk.incubator.sql2.RowPublisherOperation) TransactionCompletion(jdk.incubator.sql2.TransactionCompletion) Date(java.sql.Date) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Result(jdk.incubator.sql2.Result) RowCountOperation(jdk.incubator.sql2.RowCountOperation) ForkJoinPool(java.util.concurrent.ForkJoinPool) MultiOperation(jdk.incubator.sql2.MultiOperation) Assert(org.junit.Assert) Submission(jdk.incubator.sql2.Submission) DataSourceFactory(jdk.incubator.sql2.DataSourceFactory) MultiOperation(jdk.incubator.sql2.MultiOperation) RowOperation(jdk.incubator.sql2.RowOperation) SqlException(jdk.incubator.sql2.SqlException) DataSource(jdk.incubator.sql2.DataSource) Session(jdk.incubator.sql2.Session) Result(jdk.incubator.sql2.Result) Test(org.junit.Test)

Example 42 with Result

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());
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) TestConfig(com.oracle.adbaoverjdbc.test.TestConfig) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Result(jdk.incubator.sql2.Result) Flow(java.util.concurrent.Flow) Assert(org.junit.Assert) Session(jdk.incubator.sql2.Session) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) List(java.util.List) Flow(java.util.concurrent.Flow) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Example 43 with Result

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));
}
Also used : BeforeClass(org.junit.BeforeClass) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) TestConfig(com.oracle.adbaoverjdbc.test.TestConfig) BiConsumer(java.util.function.BiConsumer) Collector(java.util.stream.Collector) Session(jdk.incubator.sql2.Session) SqlSkippedException(jdk.incubator.sql2.SqlSkippedException) AfterClass(org.junit.AfterClass) Assert.assertNotNull(org.junit.Assert.assertNotNull) AdbaType(jdk.incubator.sql2.AdbaType) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) TransactionOutcome(jdk.incubator.sql2.TransactionOutcome) BinaryOperator(java.util.function.BinaryOperator) ArrayRowCountOperation(jdk.incubator.sql2.ArrayRowCountOperation) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) List(java.util.List) Result(jdk.incubator.sql2.Result) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) Collections(java.util.Collections) Submission(jdk.incubator.sql2.Submission) Assert.assertEquals(org.junit.Assert.assertEquals) ArrayList(java.util.ArrayList) List(java.util.List) DataSource(jdk.incubator.sql2.DataSource) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Example 44 with Result

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);
    }
}
Also used : AttributeAssignment(org.wso2.balana.ctx.AttributeAssignment) Status(org.wso2.balana.ctx.Status) ResponseWriteException(org.wso2.carbon.identity.entitlement.endpoint.exception.ResponseWriteException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) URI(java.net.URI) ResponseCtx(org.wso2.balana.ctx.ResponseCtx) AbstractResult(org.wso2.balana.ctx.AbstractResult) ObligationResult(org.wso2.balana.ObligationResult) Result(org.wso2.balana.ctx.xacml3.Result) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) Advice(org.wso2.balana.xacml3.Advice) AbstractResult(org.wso2.balana.ctx.AbstractResult) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 45 with Result

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);
    }
}
Also used : Status(org.geotoolkit.wps.xml.v200.Status) LegacyStatus(org.geotoolkit.wps.xml.v100.LegacyStatus) ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) ExceptionResponse(org.geotoolkit.ows.xml.ExceptionResponse) StatusInfo(org.geotoolkit.wps.xml.v200.StatusInfo) DismissProcessException(org.geotoolkit.process.DismissProcessException) Result(org.geotoolkit.wps.xml.v200.Result)

Aggregations

Test (org.junit.Test)46 Result (edu.stanford.CVC4.Result)35 Expr (edu.stanford.CVC4.Expr)32 SExpr (edu.stanford.CVC4.SExpr)32 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)31 Rational (edu.stanford.CVC4.Rational)25 Result (com.opensymphony.xwork2.Result)18 List (java.util.List)15 ArrayList (java.util.ArrayList)13 ArrayType (edu.stanford.CVC4.ArrayType)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 TimeUnit (java.util.concurrent.TimeUnit)8 DataSource (jdk.incubator.sql2.DataSource)8 Result (jdk.incubator.sql2.Result)8 Session (jdk.incubator.sql2.Session)8 AfterClass (org.junit.AfterClass)8 BeforeClass (org.junit.BeforeClass)8 BitVectorType (edu.stanford.CVC4.BitVectorType)6 SortType (edu.stanford.CVC4.SortType)6 Type (edu.stanford.CVC4.Type)6