Search in sources :

Example 1 with RowPublisherOperation

use of jdk.incubator.sql2.RowPublisherOperation in project oracle-db-examples by oracle.

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 2 with RowPublisherOperation

use of jdk.incubator.sql2.RowPublisherOperation in project oracle-db-examples by oracle.

the class RowPublisherOperationTest method slowRowSubscriberRequestOnThread.

@Test
public void slowRowSubscriberRequestOnThread() throws Exception {
    System.out.println("slowRowSubscriberRequestOnThread");
    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, true);
    try (Session session = getSession()) {
        cs = session.<List<String>>rowPublisherOperation(sql).subscribe(subscriber, result).onError(e -> e.printStackTrace()).timeout(getTimeout()).submit().getCompletionStage();
    }
    cs.toCompletableFuture().get(getTimeout().toMillis() + 7000, TimeUnit.MILLISECONDS);
    List<String> names = result.get(getTimeout().toMillis(), TimeUnit.MILLISECONDS);
    assertNotNull(names);
    assertFalse(names.isEmpty());
    assertEquals(14, names.size());
}
Also used : 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 3 with RowPublisherOperation

use of jdk.incubator.sql2.RowPublisherOperation in project oracle-db-examples by oracle-samples.

the class MultiOperationTest method multiRowPublisherOperation.

@Test
public void multiRowPublisherOperation() throws Exception {
    fail("TODO: Fix this test");
    String sql = "select id, name from forum_user";
    CompletableFuture<List<String>> result = new CompletableFuture<>();
    CompletionStage<List<String>> cs = null;
    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(sql).onError(t -> {
            fail(t.toString());
        });
        RowPublisherOperation rowPublisherOp = multiOp.rowPublisherOperation();
        multiOp.submit();
        Flow.Subscriber<Result.RowColumn> subscriber = getSubscriber(result, false);
        cs = rowPublisherOp.subscribe(subscriber, result).onError(e -> fail(e.toString())).timeout(TestConfig.getTimeout()).submit().getCompletionStage();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    List<String> names = result.get(TestConfig.getTimeout().toMillis(), TimeUnit.MILLISECONDS);
    assertTrue(names != null && !names.isEmpty());
}
Also used : DataSourceFactory(jdk.incubator.sql2.DataSourceFactory) SqlException(jdk.incubator.sql2.SqlException) DataSource(jdk.incubator.sql2.DataSource) Flow(java.util.concurrent.Flow) CompletableFuture(java.util.concurrent.CompletableFuture) MultiOperation(jdk.incubator.sql2.MultiOperation) ArrayList(java.util.ArrayList) List(java.util.List) RowPublisherOperation(jdk.incubator.sql2.RowPublisherOperation) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Example 4 with RowPublisherOperation

use of jdk.incubator.sql2.RowPublisherOperation in project oracle-db-examples by oracle-samples.

the class RowPublisherOperationTest method slowRowSubscriberRequestOnThread.

@Test
public void slowRowSubscriberRequestOnThread() throws Exception {
    System.out.println("slowRowSubscriberRequestOnThread");
    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, true);
    try (Session session = getSession()) {
        cs = session.<List<String>>rowPublisherOperation(sql).subscribe(subscriber, result).onError(e -> e.printStackTrace()).timeout(getTimeout()).submit().getCompletionStage();
    }
    cs.toCompletableFuture().get(getTimeout().toMillis() + 7000, TimeUnit.MILLISECONDS);
    List<String> names = result.get(getTimeout().toMillis(), TimeUnit.MILLISECONDS);
    assertNotNull(names);
    assertFalse(names.isEmpty());
    assertEquals(14, names.size());
}
Also used : 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 5 with RowPublisherOperation

use of jdk.incubator.sql2.RowPublisherOperation 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)

Aggregations

ArrayList (java.util.ArrayList)6 List (java.util.List)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Flow (java.util.concurrent.Flow)6 Session (jdk.incubator.sql2.Session)6 Test (org.junit.Test)6 DataSource (jdk.incubator.sql2.DataSource)4 TestConfig (com.oracle.adbaoverjdbc.test.TestConfig)2 CompletionStage (java.util.concurrent.CompletionStage)2 TimeUnit (java.util.concurrent.TimeUnit)2 DataSourceFactory (jdk.incubator.sql2.DataSourceFactory)2 MultiOperation (jdk.incubator.sql2.MultiOperation)2 Result (jdk.incubator.sql2.Result)2 RowPublisherOperation (jdk.incubator.sql2.RowPublisherOperation)2 SqlException (jdk.incubator.sql2.SqlException)2 AfterClass (org.junit.AfterClass)2 Assert (org.junit.Assert)2 BeforeClass (org.junit.BeforeClass)2