Search in sources :

Example 1 with ZeebeDbTransaction

use of io.camunda.zeebe.db.ZeebeDbTransaction in project zeebe-process-test by camunda.

the class InMemoryZeebeDbTransactionTest method shouldStartNewTransaction.

@Test
void shouldStartNewTransaction() throws Exception {
    // given
    oneKey.wrapLong(1);
    oneValue.wrapLong(-1);
    twoKey.wrapLong(52000);
    twoValue.wrapLong(192313);
    threeKey.wrapLong(Short.MAX_VALUE);
    threeValue.wrapLong(Integer.MAX_VALUE);
    final ZeebeDbTransaction transaction = transactionContext.getCurrentTransaction();
    transaction.run(() -> {
        oneColumnFamily.put(oneKey, oneValue);
        twoColumnFamily.put(twoKey, twoValue);
        threeColumnFamily.put(threeKey, threeValue);
    });
    // when
    transaction.commit();
    // then
    assertThat(oneColumnFamily.exists(oneKey)).isTrue();
    assertThat(twoColumnFamily.exists(twoKey)).isTrue();
    assertThat(threeColumnFamily.exists(threeKey)).isTrue();
    assertThat(((InMemoryDbTransaction) transaction).isInCurrentTransaction()).isFalse();
}
Also used : ZeebeDbTransaction(io.camunda.zeebe.db.ZeebeDbTransaction) Test(org.junit.jupiter.api.Test)

Example 2 with ZeebeDbTransaction

use of io.camunda.zeebe.db.ZeebeDbTransaction in project zeebe-process-test by camunda.

the class InMemoryZeebeDbTransactionTest method shouldNotReopenTransactionWithOperations.

@Test
void shouldNotReopenTransactionWithOperations() {
    // given
    oneKey.wrapLong(1);
    oneValue.wrapLong(-1);
    twoKey.wrapLong(52000);
    twoValue.wrapLong(192313);
    threeKey.wrapLong(Short.MAX_VALUE);
    threeValue.wrapLong(Integer.MAX_VALUE);
    transactionContext.runInTransaction(() -> {
        // when
        final ZeebeDbTransaction sameTransaction = transactionContext.getCurrentTransaction();
        sameTransaction.run(() -> {
            oneColumnFamily.put(oneKey, oneValue);
            twoColumnFamily.put(twoKey, twoValue);
            threeColumnFamily.put(threeKey, threeValue);
        });
        assertThat(oneColumnFamily.exists(oneKey)).isTrue();
        oneColumnFamily.delete(oneKey);
        assertThat(twoColumnFamily.exists(twoKey)).isTrue();
        assertThat(threeColumnFamily.exists(threeKey)).isTrue();
    });
    // then it is committed but available in this transaction
    assertThat(oneColumnFamily.exists(oneKey)).isFalse();
    assertThat(twoColumnFamily.exists(twoKey)).isTrue();
    assertThat(threeColumnFamily.exists(threeKey)).isTrue();
}
Also used : ZeebeDbTransaction(io.camunda.zeebe.db.ZeebeDbTransaction) Test(org.junit.jupiter.api.Test)

Example 3 with ZeebeDbTransaction

use of io.camunda.zeebe.db.ZeebeDbTransaction in project zeebe-process-test by camunda.

the class InMemoryZeebeDbTransactionTest method shouldAccessOnOpenTransaction.

@Test
void shouldAccessOnOpenTransaction() throws Exception {
    // given
    oneKey.wrapLong(1);
    oneValue.wrapLong(-1);
    twoKey.wrapLong(52000);
    twoValue.wrapLong(192313);
    threeKey.wrapLong(Short.MAX_VALUE);
    threeValue.wrapLong(Integer.MAX_VALUE);
    final ZeebeDbTransaction transaction = transactionContext.getCurrentTransaction();
    transaction.run(() -> {
        oneColumnFamily.put(oneKey, oneValue);
        twoColumnFamily.put(twoKey, twoValue);
        threeColumnFamily.put(threeKey, threeValue);
    });
    // when
    // no commit
    // then
    // uses the same transaction
    assertThat(oneColumnFamily.exists(oneKey)).isTrue();
    assertThat(twoColumnFamily.exists(twoKey)).isTrue();
    assertThat(threeColumnFamily.exists(threeKey)).isTrue();
}
Also used : ZeebeDbTransaction(io.camunda.zeebe.db.ZeebeDbTransaction) Test(org.junit.jupiter.api.Test)

Example 4 with ZeebeDbTransaction

use of io.camunda.zeebe.db.ZeebeDbTransaction in project zeebe by camunda.

the class ZeebeRocksDbTransactionTest method shouldReThrowExceptionFromTransactionRun.

@Test(expected = RocksDBException.class)
public void shouldReThrowExceptionFromTransactionRun() throws Exception {
    // given
    final Status status = new Status(Code.NotSupported, SubCode.None, "");
    // when
    final ZeebeDbTransaction currentTransaction = transactionContext.getCurrentTransaction();
    currentTransaction.run(() -> {
        throw new RocksDBException("expected", status);
    });
}
Also used : Status(org.rocksdb.Status) ZeebeDbTransaction(io.camunda.zeebe.db.ZeebeDbTransaction) RocksDBException(org.rocksdb.RocksDBException) Test(org.junit.Test)

Example 5 with ZeebeDbTransaction

use of io.camunda.zeebe.db.ZeebeDbTransaction in project zeebe by camunda.

the class DbTransactionTest method shouldRollbackTransaction.

@Test
public void shouldRollbackTransaction() throws Exception {
    // given
    oneKey.wrapLong(1);
    oneValue.wrapLong(-1);
    twoKey.wrapLong(52000);
    twoValue.wrapLong(192313);
    threeKey.wrapLong(Short.MAX_VALUE);
    threeValue.wrapLong(Integer.MAX_VALUE);
    final ZeebeDbTransaction transaction = transactionContext.getCurrentTransaction();
    transaction.run(() -> {
        oneColumnFamily.insert(oneKey, oneValue);
        twoColumnFamily.insert(twoKey, twoValue);
        threeColumnFamily.insert(threeKey, threeValue);
    });
    // when
    transaction.rollback();
    // then
    assertThat(oneColumnFamily.exists(oneKey)).isFalse();
    assertThat(twoColumnFamily.exists(twoKey)).isFalse();
    assertThat(threeColumnFamily.exists(threeKey)).isFalse();
}
Also used : ZeebeDbTransaction(io.camunda.zeebe.db.ZeebeDbTransaction) Test(org.junit.Test)

Aggregations

ZeebeDbTransaction (io.camunda.zeebe.db.ZeebeDbTransaction)34 Test (org.junit.Test)24 Test (org.junit.jupiter.api.Test)10 RocksDBException (org.rocksdb.RocksDBException)9 Status (org.rocksdb.Status)9 RecoverableException (io.camunda.zeebe.util.exception.RecoverableException)3