Search in sources :

Example 11 with SalesAreaRow

use of com.cadenzauk.siesta.model.SalesAreaRow in project siesta by cadenzauk.

the class ExceptionIntegrationTest method numericOverflowOnInsert.

@Test
void numericOverflowOnInsert() {
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("NZ").salesCount(Optional.of(Integer.MAX_VALUE + 1L)).build();
    calling(() -> database.insert(salesArea)).shouldThrow(RuntimeSqlException.class).with(subclass(InvalidValueException.class)).withMessage(startsWith("Incorrect data value for data type while executing 'insert into "));
}
Also used : TestDatabase(com.cadenzauk.siesta.model.TestDatabase) IncorrectSalesAreaRow(com.cadenzauk.siesta.model.IncorrectSalesAreaRow) SalesAreaRow(com.cadenzauk.siesta.model.SalesAreaRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with SalesAreaRow

use of com.cadenzauk.siesta.model.SalesAreaRow in project siesta by cadenzauk.

the class ExceptionIntegrationTest method lockTimeoutOnInsert.

@Test
void lockTimeoutOnInsert() {
    assumeTrue(dialect.supportsLockTimeout(), "Database does not support lock timeouts.");
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("NZ").build();
    try (CompositeAutoCloseable closer = new CompositeAutoCloseable()) {
        Transaction transaction1 = closer.add(database.beginTransaction());
        database.insert(transaction1, salesArea);
        Transaction transaction2 = closer.add(database.beginTransaction());
        closer.add(database.withLockTimeout(transaction2, 0, TimeUnit.MILLISECONDS));
        calling(() -> database.insert(transaction2, salesArea)).shouldThrow(RuntimeSqlException.class).with(subclass(LockingException.class)).withMessage(startsWith("Locking failure while executing 'insert into"));
        transaction2.rollback();
    }
}
Also used : CompositeAutoCloseable(com.cadenzauk.core.lang.CompositeAutoCloseable) TestDatabase(com.cadenzauk.siesta.model.TestDatabase) IncorrectSalesAreaRow(com.cadenzauk.siesta.model.IncorrectSalesAreaRow) SalesAreaRow(com.cadenzauk.siesta.model.SalesAreaRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

IncorrectSalesAreaRow (com.cadenzauk.siesta.model.IncorrectSalesAreaRow)12 SalesAreaRow (com.cadenzauk.siesta.model.SalesAreaRow)12 TestDatabase (com.cadenzauk.siesta.model.TestDatabase)12 Test (org.junit.jupiter.api.Test)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 CompositeAutoCloseable (com.cadenzauk.core.lang.CompositeAutoCloseable)3 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)2