use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method deadlockOnUpdate.
@SuppressWarnings("ThrowableNotThrown")
@Test
void deadlockOnUpdate() {
Database database = TestDatabase.testDatabase(dataSource);
SalespersonRow salespersonRow1 = aRandomSalesperson();
SalespersonRow salespersonRow2 = aRandomSalesperson();
database.insert(salespersonRow1, salespersonRow2);
CompletableFuture<Void> wait11 = new CompletableFuture<>();
CompletableFuture<Void> wait12 = new CompletableFuture<>();
CompletableFuture<Void> wait2 = new CompletableFuture<>();
CompletableFuture<Void> wait3 = new CompletableFuture<>();
CompletableFuture<Void> wait4 = new CompletableFuture<>();
CompletableFuture<Throwable> future1 = performUpdate(database, salespersonRow1, salespersonRow2, wait11, wait2, wait3, wait4);
CompletableFuture<Throwable> future2 = performUpdate(database, salespersonRow2, salespersonRow1, wait12, wait2, wait3, wait4);
CompletableFuture.allOf(wait11, wait12).join();
wait2.complete(null);
wait3.join();
wait4.complete(null);
CompletableFuture.allOf(future1, future2).join();
Throwable exception = Stream.of(future1, future2).map(CompletableFuture::join).filter(Objects::nonNull).findFirst().orElseThrow(() -> new AssertionError("No exception was thrown for deadlock."));
assertThat(exception, instanceOf(LockingException.class));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method uniqueConstraintViolationOnUpdate.
@Test
void uniqueConstraintViolationOnUpdate() {
Database database = TestDatabase.testDatabase(dataSource);
SalespersonRow salespersonRow1 = aRandomSalesperson();
SalespersonRow salespersonRow2 = aRandomSalesperson();
database.insert(salespersonRow1, salespersonRow2);
calling(() -> database.update(SalespersonRow.class).set(SalespersonRow::salespersonId).to(salespersonRow1.salespersonId()).where(SalespersonRow::salespersonId).isEqualTo(salespersonRow2.salespersonId()).execute()).shouldThrow(RuntimeSqlException.class).with(subclass(DuplicateKeyException.class)).withMessage(startsWith("Unique constraint violated while executing 'update "));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method foreignKeyViolationOnDelete.
@Test
void foreignKeyViolationOnDelete() {
Database database = TestDatabase.testDatabase(dataSource);
SalespersonRow salespersonRow = aRandomSalesperson();
database.insert(salespersonRow);
SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("Far East").salespersonId(Optional.of(salespersonRow.salespersonId())).build();
database.insert(salesArea);
calling(() -> database.delete(SalespersonRow.class).where(SalespersonRow::salespersonId).isEqualTo(salespersonRow.salespersonId()).execute()).shouldThrow(RuntimeSqlException.class).with(subclass(ReferentialIntegrityException.class)).withMessage(startsWith("Foreign key constraint violated while executing 'delete "));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class OlapFunctionTest method addPartitionByAndParitionBy.
@ParameterizedTest(name = "{index}: {1}")
@MethodSource("parametersForRowNumber")
void addPartitionByAndParitionBy(BiFunction<InOlapExpectingPartitionBy<Integer>, Alias<SalespersonRow>, TypedExpression<Integer>> f, String expected, Object[] expectedArgs) {
Database database = testDatabase(new AnsiDialect());
Alias<SalespersonRow> s = database.table(SalespersonRow.class).as("s");
database.from(s).select(f.apply(Olap.rowNumber(), s)).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select row_number() over (" + expected + ") as row_number_1 " + "from SIESTA.SALESPERSON s"));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class OlapTest method olapFunction.
@ParameterizedTest(name = "{index}: {1}")
@MethodSource("parametersForOlapTest")
void olapFunction(Function<Alias<SalespersonRow>, InOlapExpectingPartitionBy<?>> f, String expectedSql) {
Database database = testDatabase(new AnsiDialect());
Alias<SalespersonRow> s = database.table(SalespersonRow.class).as("s");
Scope scope = new Scope(database, s);
InOlapExpectingPartitionBy<?> result = f.apply(s);
assertThat(result.sql(scope), is(expectedSql));
assertThat(result.precedence(), is(Precedence.UNARY));
}
Aggregations