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();
}
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();
}
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();
}
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);
});
}
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();
}
Aggregations