io.camunda.zeebe.process.test.engine.db.InMemoryDb Maven / Gradle / Ivy
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Zeebe Community License 1.1. You may not use this file
* except in compliance with the Zeebe Community License 1.1.
*/
package io.camunda.zeebe.process.test.engine.db;
import io.camunda.zeebe.db.*;
import io.camunda.zeebe.db.impl.DbNil;
import io.camunda.zeebe.protocol.EnumValue;
import java.io.File;
import java.util.Optional;
import java.util.TreeMap;
/**
* In memory implementation of {@code ZeebeDb}
*
* This implementation does not support
*
*
* - concurrent access
*
- locking between transactions
*
- Taking snapshots
*
*
* This implementation is backed by a tree map.
*
* @param
*/
final class InMemoryDb & EnumValue>
implements ZeebeDb {
private final TreeMap database = new TreeMap<>();
@Override
public
ColumnFamily createColumnFamily(
final ColumnFamilyType columnFamily,
final TransactionContext context,
final KeyType keyInstance,
final ValueType valueInstance) {
return new InMemoryDbColumnFamily<>(columnFamily, context, keyInstance, valueInstance);
}
@Override
public void createSnapshot(final File snapshotDir) {
throw new IllegalStateException("No snapshots supported");
}
@Override
public Optional getProperty(final String propertyName) {
return Optional.empty();
}
@Override
public TransactionContext createContext() {
return new InMemoryDbTransactionContext(database);
}
@Override
public boolean isEmpty(final ColumnFamilyType column, final TransactionContext context) {
return createColumnFamily(column, context, DbNullKey.INSTANCE, DbNil.INSTANCE).isEmpty();
}
@Override
public void close() {
database.clear();
}
}