Search in sources :

Example 11 with Submission

use of com.google.webrisk.v1.Submission in project java-webrisk by googleapis.

the class WebRiskServiceClientTest method createSubmissionExceptionTest.

@Test
public void createSubmissionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockWebRiskService.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        Submission submission = Submission.newBuilder().build();
        client.createSubmission(parent, submission);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Submission(com.google.webrisk.v1.Submission) ProjectName(com.google.webrisk.v1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 12 with Submission

use of com.google.webrisk.v1.Submission in project java-webrisk by googleapis.

the class SubmitUriExample method submitUriExample.

public static void submitUriExample() throws IOException {
    // The URL to be submitted
    String uri = "http://testsafebrowsing.appspot.com/s/malware.html";
    Submission response = submitUriExample(uri);
}
Also used : Submission(com.google.webrisk.v1.Submission)

Example 13 with Submission

use of com.google.webrisk.v1.Submission in project oracle-db-examples by oracle.

the class SessionTest method testOperationGroup.

@Test
public void testOperationGroup() throws Exception {
    try (DataSource ds = getDataSource();
        Session se = ds.getSession()) {
        AtomicInteger opCounter = new AtomicInteger();
        se.rowCountOperation("INSERT INTO " + OP_GROUP_TABLE + " VALUES (0)").apply(rc -> opCounter.incrementAndGet()).submit();
        Submission<List<Boolean>> opgSubmission = null;
        try (OperationGroup<Boolean, List<Boolean>> opg = se.operationGroup()) {
            opgSubmission = opg.collect(Collectors.toList()).timeout(getTimeout()).submit();
            opg.rowOperation("SELECT c FROM " + OP_GROUP_TABLE).collect(Collectors.reducing(Boolean.TRUE, row -> opCounter.compareAndSet(1, 2), (b1, b2) -> b1 && b2)).submit();
            opg.localOperation().onExecution(() -> opCounter.compareAndSet(2, 3)).submit();
            opg.rowCountOperation("UPDATE " + OP_GROUP_TABLE + " SET c = 1 WHERE c = 0").apply(rc -> opCounter.compareAndSet(3, 4)).submit();
        }
        assertNotNull(opgSubmission);
        List<Boolean> opgResult = opgSubmission.getCompletionStage().toCompletableFuture().get();
        assertNotNull(opgResult);
        assertEquals(3, opgResult.size());
        for (Boolean memberResult : opgResult) assertTrue(memberResult);
        se.rollback().toCompletableFuture().get(getTimeout().toMillis(), TimeUnit.MILLISECONDS);
    }
}
Also used : DataSourceFactory(jdk.incubator.sql2.DataSourceFactory) BeforeClass(org.junit.BeforeClass) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) TestConfig(com.oracle.adbaoverjdbc.test.TestConfig) OperationGroup(jdk.incubator.sql2.OperationGroup) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdbaSessionProperty(jdk.incubator.sql2.AdbaSessionProperty) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TransactionIsolation(jdk.incubator.sql2.AdbaSessionProperty.TransactionIsolation) Assert.fail(org.junit.Assert.fail) Session(jdk.incubator.sql2.Session) AfterClass(org.junit.AfterClass) Validation(jdk.incubator.sql2.Session.Validation) Assert.assertNotNull(org.junit.Assert.assertNotNull) Lifecycle(jdk.incubator.sql2.Session.Lifecycle) Assert.assertTrue(org.junit.Assert.assertTrue) BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test) LifecycleEvent(com.oracle.adbaoverjdbc.test.SessionTest.TestLifecycleListener.LifecycleEvent) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) TransactionCompletion(jdk.incubator.sql2.TransactionCompletion) TransactionOutcome(jdk.incubator.sql2.TransactionOutcome) Operation(jdk.incubator.sql2.Operation) SessionLifecycleListener(jdk.incubator.sql2.Session.SessionLifecycleListener) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Builder(jdk.incubator.sql2.Session.Builder) Assert.assertFalse(org.junit.Assert.assertFalse) Submission(jdk.incubator.sql2.Submission) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataSource(jdk.incubator.sql2.DataSource) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 Submission (com.google.webrisk.v1.Submission)7 TestConfig (com.oracle.adbaoverjdbc.test.TestConfig)6 List (java.util.List)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 TimeUnit (java.util.concurrent.TimeUnit)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Function (java.util.function.Function)6 Collectors (java.util.stream.Collectors)6 DataSource (jdk.incubator.sql2.DataSource)6 Session (jdk.incubator.sql2.Session)6 Submission (jdk.incubator.sql2.Submission)6 TransactionOutcome (jdk.incubator.sql2.TransactionOutcome)6 AfterClass (org.junit.AfterClass)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 Assert.assertFalse (org.junit.Assert.assertFalse)6 Assert.assertNotNull (org.junit.Assert.assertNotNull)6 Assert.assertNull (org.junit.Assert.assertNull)6 Assert.assertTrue (org.junit.Assert.assertTrue)6 BeforeClass (org.junit.BeforeClass)6