com.github.davidmoten.guavamini.Lists Java Examples
The following examples show how to use
com.github.davidmoten.guavamini.Lists.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistenceMicrowaveTest.java From state-machine with Apache License 2.0 | 6 votes |
@Test public void testGetByProperties() throws IOException { MicrowaveBehaviour<String> behaviour = createMicrowaveBehaviour(); Function<Class<?>, EntityBehaviour<?, String>> behaviourFactory = cls -> behaviour; TestExecutor executor = new TestExecutor(); Persistence p = createPersistence() // .behaviourFactory(behaviourFactory) // .propertiesFactory(Microwave.class, // m -> Lists.newArrayList(Property.create("colour", "white"))) // .executor(executor) // .build(); p.create(); p.initialize(); signal(p, new DoorOpened()); Set<EntityWithId<Microwave>> set = p.get(Microwave.class, "colour", "white"); assertEquals(1, set.size()); }
Example #2
Source File: Call.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
private static Flowable<Notification<CallableResultSetN>> createWithNResultSets(Connection con, String sql, Flowable<List<Object>> parameterGroups, List<ParameterPlaceholder> parameterPlaceholders, List<Function<? super ResultSet, ?>> functions, int fetchSize) { Callable<NamedCallableStatement> resourceFactory = () -> Util.prepareCall(con, sql, parameterPlaceholders); final Function<NamedCallableStatement, Flowable<Notification<CallableResultSetN>>> flowableFactory = // stmt -> parameterGroups // .flatMap(parameters -> { List<Object> outputValues = executeAndReturnOutputValues(parameterPlaceholders, stmt, parameters); List<Flowable<?>> flowables = Lists.newArrayList(); int i = 0; do { Function<? super ResultSet, ?> f = functions.get(i); flowables.add(createFlowable(stmt, f)); i++; } while (stmt.stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT)); return Single.just(new CallableResultSetN(outputValues, flowables)).toFlowable(); }) // .materialize() // .doOnComplete(() -> Util.commit(stmt.stmt)) // .doOnError(e -> Util.rollback(stmt.stmt)); Consumer<NamedCallableStatement> disposer = Util::closeCallableStatementAndConnection; return Flowable.using(resourceFactory, flowableFactory, disposer, true); }
Example #3
Source File: SqlInfoTest.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
@Test public void testExpansionWithParametersCollectionPresent() { Parameter p1 = new Parameter(12); Parameter p2 = new Parameter(Lists.newArrayList(1, 2, 3)); SqlInfo s = SqlInfo.parse("? hello ?", Lists.newArrayList(p1, p2)); assertEquals("? hello ?,?,?", s.sql()); }
Example #4
Source File: StringsTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testSplitLinesWithComments() { Strings.splitLinesSkipComments(StringsTest.class.getResourceAsStream("/test4.txt"), Strings.UTF_8, ",", "#") // .test() // .assertValues(Lists.newArrayList("23", "176", "FRED"), // Lists.newArrayList("13", "130", "JOHN")) .assertComplete(); }
Example #5
Source File: TransformersTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testBufferMaxCountAndTimeoutAsyncTimeoutWins() { int maxSize = 3; Flowable.just(1, 2) // .timeout(1, TimeUnit.SECONDS) // .concatWith(Flowable.just(3).delay(500, TimeUnit.MILLISECONDS)) // .compose(Transformers.<Integer>buffer(maxSize, 100, TimeUnit.MILLISECONDS)) // .test() // .awaitDone(10, TimeUnit.SECONDS) // .assertValues(Lists.newArrayList(1, 2), Lists.newArrayList(3)) // .assertComplete(); }
Example #6
Source File: TransformersTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testBufferMaxCountAndTimeoutAsyncCountWins() { int maxSize = 3; Flowable.just(1, 2, 3, 4) // .concatWith(Flowable.just(5).delay(500, TimeUnit.MILLISECONDS)) // .compose(Transformers.<Integer>buffer(maxSize, 100, TimeUnit.MILLISECONDS)) // .test() // .awaitDone(10, TimeUnit.SECONDS) // .assertValues(Lists.newArrayList(1, 2, 3), Lists.newArrayList(4), Lists.newArrayList(5)) // .assertComplete(); }
Example #7
Source File: TransformersTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testBufferMaxCountAndTimeout() { int maxSize = 3; Flowable.just(1, 2, 3) // .compose(Transformers.<Integer>buffer(maxSize, 0, TimeUnit.SECONDS, Schedulers.trampoline())).test() // .assertValues(Lists.newArrayList(1), Lists.newArrayList(2), Lists.newArrayList(3)) // .assertComplete(); }
Example #8
Source File: FlowableMinRequestTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testRebatchRequestsMinLessThanMax() { List<Long> requests = new CopyOnWriteArrayList<Long>(); Flowable.range(1, 10) // .doOnRequest(Consumers.addLongTo(requests)) // .compose(Transformers.rebatchRequests(2, 3, false)) // .test(10) // .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // .assertComplete(); assertEquals(Lists.newArrayList(3L, 3L, 3L, 2L), requests); }
Example #9
Source File: FlowableMinRequestTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testRebatchRequestsMinEqualsMaxDontConstrainFirstRequest() { List<Long> requests = new CopyOnWriteArrayList<Long>(); Flowable.range(1, 10) // .doOnRequest(Consumers.addLongTo(requests)) // .compose(Transformers.rebatchRequests(5, 5, false)) // .test() // .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // .assertComplete(); assertEquals(Lists.newArrayList(5L, 5L), requests); }
Example #10
Source File: FlowableMinRequestTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testRebatchRequestsMinEqualsMaxDontConstrainFirstUsesRxJavaCoreRebatchRequests() { List<Long> requests = new CopyOnWriteArrayList<Long>(); Flowable.range(1, 10) // .doOnRequest(Consumers.addLongTo(requests)) // .compose(Transformers.rebatchRequests(5, 5)) // .test() // .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // .assertComplete(); assertEquals(Lists.newArrayList(5L, 4L, 4L), requests); }
Example #11
Source File: FlowableMinRequestTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testError() { List<Long> requests = new CopyOnWriteArrayList<Long>(); Flowable.<Long>error(new ThrowingException()) // .doOnRequest(Consumers.addLongTo(requests)) // .compose(Transformers.minRequest(2)) // .test() // .assertNoValues() // .assertError(ThrowingException.class); assertEquals(Lists.newArrayList(Long.MAX_VALUE), requests); }
Example #12
Source File: FlowableMinRequestTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testBackpressure() { List<Long> requests = new CopyOnWriteArrayList<Long>(); Flowable.range(1, 10) // .doOnRequest(Consumers.addLongTo(requests)) // .compose(Transformers.minRequest(2)) // .test(1) // .assertValues(1) // .requestMore(9) // .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // .assertComplete(); assertEquals(Lists.newArrayList(2L, 8L), requests); }
Example #13
Source File: FlowableMinRequestTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testMinWhenRequestIsMaxValueAndSourceDoesNotComplete() { List<Long> requests = new CopyOnWriteArrayList<Long>(); Flowable.range(1, 10) // .concatWith(Flowable.<Integer>never()) // .doOnRequest(Consumers.addLongTo(requests)) // .compose(Transformers.minRequest(2)) // .test() // .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // .assertNotComplete(); assertEquals(Lists.newArrayList(Long.MAX_VALUE), requests); }
Example #14
Source File: FlowableMinRequestTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testMinWhenRequestIsMaxValue() { List<Long> requests = new CopyOnWriteArrayList<Long>(); Flowable.range(1, 10) // .doOnRequest(Consumers.addLongTo(requests)) // .compose(Transformers.minRequest(2)) // .test() // .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // .assertComplete(); assertEquals(Lists.newArrayList(Long.MAX_VALUE), requests); }
Example #15
Source File: FlowableMinRequestTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testUnconstrainedFirstRequest() { List<Long> requests = new CopyOnWriteArrayList<Long>(); Flowable.range(1, 10) // .doOnRequest(Consumers.addLongTo(requests)) // .compose(Transformers.minRequest(1, 2)) // .rebatchRequests(1) // .test() // .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // .assertComplete(); assertEquals(Lists.newArrayList(1L, 2L, 2L, 2L, 2L, 2L), requests); }
Example #16
Source File: FlowableMinRequestTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Test public void testConstrainedFirstRequest() { List<Long> requests = new CopyOnWriteArrayList<Long>(); Flowable.range(1, 10) // .doOnRequest(Consumers.addLongTo(requests)) // .compose(Transformers.minRequest(2)) // .rebatchRequests(1) // .test() // .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // .assertComplete(); assertEquals(Lists.newArrayList(2L, 2L, 2L, 2L, 2L), requests); }
Example #17
Source File: DatabaseTest.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
@Test(timeout = 5000) public void testSelectConcurrencyTest() throws InterruptedException, TimeoutException { debug(); try { try (Database db = db(1)) { Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(2)); int n = 2; CountDownLatch latch = new CountDownLatch(n); AtomicInteger count = new AtomicInteger(); for (int i = 0; i < n; i++) { db.select("select score from person where name=?") // .parameters("FRED", "JOSEPH") // .getAs(Integer.class) // .subscribeOn(scheduler) // .toList() // .doOnSuccess(x -> { if (!x.equals(Lists.newArrayList(21, 34))) { throw new RuntimeException("run broken"); } }) // .doOnSuccess(x -> { count.incrementAndGet(); latch.countDown(); }) // .doOnError(x -> latch.countDown()) // .subscribe(); log.info("submitted " + i); } if (!latch.await(5000, TimeUnit.SECONDS)) { throw new TimeoutException("timeout"); } assertEquals(n, count.get()); } } finally { debug(); } }
Example #18
Source File: DatabaseTest.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
@Test(timeout = 40000) public void testSelectUsingNonBlockingBuilderConcurrencyTest() throws InterruptedException, TimeoutException { info(); try { try (Database db = db(3)) { Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(50)); int n = 10000; CountDownLatch latch = new CountDownLatch(n); AtomicInteger count = new AtomicInteger(); for (int i = 0; i < n; i++) { db.select("select score from person where name=?") // .parameters("FRED", "JOSEPH") // .getAs(Integer.class) // .subscribeOn(scheduler) // .toList() // .doOnSuccess(x -> { if (!x.equals(Lists.newArrayList(21, 34))) { throw new RuntimeException("run broken"); } else { // log.debug(iCopy + " succeeded"); } }) // .doOnSuccess(x -> { count.incrementAndGet(); latch.countDown(); }) // .doOnError(x -> latch.countDown()) // .subscribe(); } if (!latch.await(20, TimeUnit.SECONDS)) { throw new TimeoutException("timeout"); } assertEquals(n, count.get()); } } finally { debug(); } }
Example #19
Source File: DatabaseTest.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
@Test public void testSelectUsingInClauseWithRepeatedNamedListParameterAndRepeatedNonListParameter() { Database.test() // .select("select score from person where name in (:names) and score >:score and name in (:names) and score >:score order by score") // .parameter("names", Lists.newArrayList("FRED", "JOSEPH")) // .parameter("score", 0) // .getAs(Integer.class) // .test() // .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) // .assertNoErrors() // .assertValues(21, 34) // .assertComplete(); }
Example #20
Source File: DatabaseTest.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
@Test public void testSelectUsingInClauseWithRepeatedNamedListParameter() { Database.test() // .select("select score from person where name in (:names) and name in (:names) order by score") // .parameter("names", Lists.newArrayList("FRED", "JOSEPH")) // .getAs(Integer.class) // .test() // .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) // .assertNoErrors() // .assertValues(21, 34) // .assertComplete(); }
Example #21
Source File: DatabaseTest.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
@Test public void testSelectUsingInClauseWithNamedListParameter() { Database.test() // .select("select score from person where score > :score and name in (:names) order by score") // .parameter("score", 0) // .parameter("names", Lists.newArrayList("FRED", "JOSEPH")) // .getAs(Integer.class) // .test() // .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) // .assertNoErrors() // .assertValues(21, 34) // .assertComplete(); }
Example #22
Source File: DatabaseTest.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
@Test public void testSelectUsingInClauseWithListParameter() { Database.test() // .select("select score from person where score > ? and name in (?) order by score") // .parameters(0, Lists.newArrayList("FRED", "JOSEPH")) // .getAs(Integer.class) // .test() // .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) // .assertNoErrors() // .assertValues(21, 34) // .assertComplete(); }
Example #23
Source File: UtilTest.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
@Test(expected = SQLException.class) public void testPsThrowsInSetParameters() throws SQLException { boolean namesAllowed = true; List<Parameter> list = Lists.newArrayList(Parameter.create("name", "FRED")); PreparedStatement ps = Mockito.mock(PreparedStatement.class); try { Mockito.doThrow(new SQLException("boo")) // .when(ps) // .setObject(Mockito.anyInt(), Mockito.any()); Util.setParameters(ps, list, namesAllowed); } finally { Mockito.verify(ps, Mockito.atMost(1)).setObject(Mockito.anyInt(), Mockito.any()); } }
Example #24
Source File: CallableBuilder.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
public CallableBuilderN inOut(Type type, Class<T3> cls5) { b.inOut(type, cls5); return new CallableBuilderN(b, Lists.newArrayList(cls1, cls2, cls3, cls4, cls5)); }
Example #25
Source File: SqlInfoTest.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
@Test public void testExpansionWithParametersNoCollections() { Parameter p = new Parameter(12); SqlInfo s = SqlInfo.parse("? hello ?", Lists.newArrayList(p, p)); assertEquals("? hello ?", s.sql()); }
Example #26
Source File: Parameter.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
public static ParameterListBuilder named(String name, String value) { return new ParameterListBuilder(Lists.newArrayList()).named(name, value); }
Example #27
Source File: TransactedCallableBuilder.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public CallableResultSetsNBuilder get(Function<? super ResultSet, ?> f5) { return new CallableResultSetsNBuilder(b, Lists.newArrayList(f1, f2, f3, f4, f5)); }
Example #28
Source File: TransactedCallableBuilder.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
public CallableBuilderN out(Type type, Class<?> cls5) { b.out(type, cls5); return new CallableBuilderN(b, Lists.newArrayList(cls1, cls2, cls3, cls4, cls5)); }
Example #29
Source File: TransactedCallableBuilder.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
public CallableBuilderN inOut(Type type, Class<T3> cls5) { b.inOut(type, cls5); return new CallableBuilderN(b, Lists.newArrayList(cls1, cls2, cls3, cls4, cls5)); }
Example #30
Source File: CallableBuilder.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public CallableResultSetsNBuilder get(Function<? super ResultSet, ?> f5) { return new CallableResultSetsNBuilder(b, Lists.newArrayList(f1, f2, f3, f4, f5)); }