@Test public void should_dsl_select_slice_async() throws Exception { // Given final Map<String, Object> values = new HashMap<>(); final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); values.put("id", id); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); final Date date1 = dateFormat.parse("2015-10-01 00:00:00 GMT"); final Date date9 = dateFormat.parse("2015-10-09 00:00:00 GMT"); values.put("date1", "'2015-10-01 00:00:00+0000'"); values.put("date2", "'2015-10-02 00:00:00+0000'"); values.put("date3", "'2015-10-03 00:00:00+0000'"); values.put("date4", "'2015-10-04 00:00:00+0000'"); values.put("date5", "'2015-10-05 00:00:00+0000'"); values.put("date6", "'2015-10-06 00:00:00+0000'"); values.put("date7", "'2015-10-07 00:00:00+0000'"); values.put("date8", "'2015-10-08 00:00:00+0000'"); values.put("date9", "'2015-10-09 00:00:00+0000'"); scriptExecutor.executeScriptTemplate("SimpleEntity/insert_many_rows.cql", values); final CountDownLatch latch = new CountDownLatch(1); final CassandraLogAsserter logAsserter = new CassandraLogAsserter(); logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n"); // When final CompletableFuture<List<SimpleEntity>> future = manager .dsl() .select() .consistencyList() .simpleSet() .simpleMap() .value() .simpleMap() .fromBaseTable() .where() .id() .Eq(id) .date() .Gte_And_Lt(date1, date9) .withResultSetAsyncListener( rs -> { LOGGER.info(CALLED); latch.countDown(); return rs; }) .withTracing() .getListAsync(); // Then latch.await(); assertThat(future.get()).hasSize(8); logAsserter.assertContains("Called - [achilles-default-executor"); }
@Test public void should_dsl_update_value_async() throws Exception { // Given final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); final Date date = buildDateKey(); final AtomicBoolean success = new AtomicBoolean(false); scriptExecutor.executeScriptTemplate( "SimpleEntity/insert_single_row.cql", ImmutableMap.of("id", id, "table", "simple")); final CountDownLatch latch = new CountDownLatch(1); final CassandraLogAsserter logAsserter = new CassandraLogAsserter(); logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n"); // When manager .dsl() .update() .fromBaseTable() .value() .Set("new value") .where() .id() .Eq(id) .date() .Eq(date) .if_Value() .Eq("0 AM") .withLwtResultListener( new LWTResultListener() { @Override public void onSuccess() { success.getAndSet(true); } @Override public void onError(LWTResult lwtResult) {} }) .withResultSetAsyncListener( rs -> { LOGGER.info(CALLED); latch.countDown(); return rs; }) .executeAsync(); // Then latch.await(); logAsserter.assertContains("Called - [achilles-default-executor"); }
@Test public void should_dsl_delete_async() throws Exception { // Given final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); final Date date = buildDateKey(); scriptExecutor.executeScriptTemplate( "SimpleEntity/insert_single_row.cql", ImmutableMap.of("id", id, "table", "simple")); final CountDownLatch latch = new CountDownLatch(1); final CassandraLogAsserter logAsserter = new CassandraLogAsserter(); logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n"); // When manager .dsl() .delete() .consistencyList() .simpleMap() .fromBaseTable() .where() .id() .Eq(id) .date() .Eq(date) .withResultSetAsyncListener( rs -> { LOGGER.info(CALLED); latch.countDown(); return rs; }) .withTracing() .executeAsync(); // Then latch.await(); logAsserter.assertContains("Called - "); }