use of io.lettuce.core.dynamic.batch.BatchException in project lettuce-core by lettuce-io.
the class BatchExecutableCommand method synchronize.
protected static Object synchronize(BatchTasks batchTasks, StatefulConnection<Object, Object> connection) {
if (batchTasks == BatchTasks.EMPTY) {
return null;
}
Duration timeout = connection.getTimeout();
BatchException exception = null;
List<RedisCommand<?, ?, ?>> failures = null;
for (RedisCommand<?, ?, ?> batchTask : batchTasks) {
try {
Futures.await(timeout, (RedisFuture) batchTask);
} catch (Exception e) {
if (exception == null) {
failures = new ArrayList<>();
exception = new BatchException(failures);
}
failures.add(batchTask);
exception.addSuppressed(e);
}
}
if (exception != null) {
throw exception;
}
return null;
}
use of io.lettuce.core.dynamic.batch.BatchException in project lettuce-core by lettuce-io.
the class RedisCommandsBatchingIntegrationTests method shouldHandleSynchronousBatchErrors.
@Test
void shouldHandleSynchronousBatchErrors() {
RedisCommandFactory factory = new RedisCommandFactory(redis.getStatefulConnection());
Batching api = factory.getCommands(Batching.class);
api.set("k1", value);
api.set("k2", value);
api.llen("k2");
api.set("k4", value);
assertThat(redis.get("k1")).isNull();
try {
api.llen("k4");
fail("Missing BatchException");
} catch (BatchException e) {
assertThat(redis.get("k1")).isEqualTo(value);
assertThat(redis.get("k4")).isEqualTo(value);
assertThat(e).isInstanceOf(BatchException.class);
assertThat(e.getSuppressed()).hasSize(2);
assertThat(e.getFailedCommands()).hasSize(2);
}
}
Aggregations