dev.responsive.kafka.store.TTDKeyValueSchema Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of responsive-test-utils Show documentation
Show all versions of responsive-test-utils Show documentation
artifact for responsive-test-utils
/*
* Copyright 2023 Responsive Computing, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.responsive.kafka.store;
import com.datastax.oss.driver.api.core.cql.BoundStatement;
import dev.responsive.db.RemoteKeyValueSchema;
import dev.responsive.kafka.clients.TTDCassandraClient;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.apache.kafka.common.utils.Bytes;
import org.apache.kafka.streams.state.KeyValueIterator;
public class TTDKeyValueSchema extends TTDSchema implements RemoteKeyValueSchema {
private final Map tableNameToStore = new HashMap<>();
public TTDKeyValueSchema(final TTDCassandraClient client) {
super(client);
}
@Override
public void create(final String tableName, final Optional ttl) {
tableNameToStore.put(tableName, new KVStoreStub(ttl.orElse(null), time));
}
@Override
public long count(final String tableName) {
return tableNameToStore.containsKey(tableName) ? tableNameToStore.get(tableName).count() : 0L;
}
@Override
public BoundStatement insert(
final String tableName,
final int partitionKey,
final Bytes key,
final byte[] value,
final long epochMillis
) {
tableNameToStore.get(tableName).put(key, value);
return null;
}
@Override
public BoundStatement delete(final String tableName, final int partitionKey, final Bytes key) {
tableNameToStore.get(tableName).delete(key);
return null;
}
@Override
public byte[] get(final String tableName, final int partition, final Bytes key, long minValidTs) {
return tableNameToStore.get(tableName).get(key);
}
@Override
public KeyValueIterator range(
final String tableName,
final int partition,
Bytes from,
final Bytes to,
long minValidTs) {
return tableNameToStore.get(tableName).range(from, to);
}
@Override
public KeyValueIterator all(final String tableName, final int partition,
long minValidTs) {
return tableNameToStore.get(tableName).all();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy