Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package io.aiven.inkless.storage_backend.in_memory;

import org.apache.kafka.common.metrics.Metrics;
import org.apache.kafka.common.utils.Time;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -47,8 +46,8 @@ public final class InMemoryStorage extends StorageBackend {
private final ConcurrentHashMap<ObjectKey, byte[]> storage = new ConcurrentHashMap<>();

// needed for reflection based instantiation
public InMemoryStorage() {
super(new Metrics(Time.SYSTEM));
public InMemoryStorage(final Metrics metrics) {
super(metrics);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package io.aiven.inkless.storage_backend.in_memory;

import org.apache.kafka.common.metrics.Metrics;

import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
Expand All @@ -39,7 +41,8 @@ class InMemoryStorageTest {

@Test
void fetchNulls() {
final InMemoryStorage storage = new InMemoryStorage();
final Metrics metrics = new Metrics();
final InMemoryStorage storage = new InMemoryStorage(metrics);
assertThatThrownBy(() -> storage.fetch(null, new ByteRange(0, 10)))
.isInstanceOf(NullPointerException.class)
.hasMessage("key cannot be null");
Expand All @@ -50,7 +53,8 @@ void fetchNulls() {

@Test
void deleteNulls() {
final InMemoryStorage storage = new InMemoryStorage();
final Metrics metrics = new Metrics();
final InMemoryStorage storage = new InMemoryStorage(metrics);
assertThatThrownBy(() -> storage.delete((ObjectKey) null))
.isInstanceOf(NullPointerException.class)
.hasMessage("key cannot be null");
Expand All @@ -61,14 +65,16 @@ void deleteNulls() {

@Test
void fetchNonExistent() {
final InMemoryStorage storage = new InMemoryStorage();
final Metrics metrics = new Metrics();
final InMemoryStorage storage = new InMemoryStorage(metrics);
assertThatThrownBy(() -> storage.fetch(OBJECT_KEY, ByteRange.maxRange()))
.isInstanceOf(KeyNotFoundException.class);
}

@Test
void uploadAndFetch() throws StorageBackendException, IOException {
final InMemoryStorage storage = new InMemoryStorage();
final Metrics metrics = new Metrics();
final InMemoryStorage storage = new InMemoryStorage(metrics);
final byte[] data = new byte[10];
storage.upload(OBJECT_KEY, new ByteArrayInputStream(data), data.length);

Expand All @@ -79,7 +85,8 @@ void uploadAndFetch() throws StorageBackendException, IOException {

@Test
void fetchRanged() throws StorageBackendException, IOException {
final InMemoryStorage storage = new InMemoryStorage();
final Metrics metrics = new Metrics();
final InMemoryStorage storage = new InMemoryStorage(metrics);
final byte[] data = new byte[]{0, 1, 2, 3, 4, 5, 6, 7};
storage.upload(OBJECT_KEY, new ByteArrayInputStream(data), data.length);

Expand All @@ -92,7 +99,8 @@ void fetchRanged() throws StorageBackendException, IOException {

@Test
void fetchOutsideOfSize() throws StorageBackendException {
final InMemoryStorage storage = new InMemoryStorage();
final Metrics metrics = new Metrics();
final InMemoryStorage storage = new InMemoryStorage(metrics);
final byte[] data = new byte[]{0, 1, 2, 3, 4, 5, 6, 7};
storage.upload(OBJECT_KEY, new ByteArrayInputStream(data), data.length);

Expand All @@ -103,7 +111,8 @@ void fetchOutsideOfSize() throws StorageBackendException {

@Test
void delete() throws StorageBackendException, IOException {
final InMemoryStorage storage = new InMemoryStorage();
final Metrics metrics = new Metrics();
final InMemoryStorage storage = new InMemoryStorage(metrics);
final byte[] data = new byte[]{0, 1, 2, 3, 4, 5, 6, 7};
storage.upload(OBJECT_KEY, new ByteArrayInputStream(data), data.length);

Expand All @@ -118,7 +127,8 @@ void delete() throws StorageBackendException, IOException {

@Test
void deleteMany() throws StorageBackendException, IOException {
final InMemoryStorage storage = new InMemoryStorage();
final Metrics metrics = new Metrics();
final InMemoryStorage storage = new InMemoryStorage(metrics);
final byte[] data = new byte[]{0, 1, 2, 3, 4, 5, 6, 7};
storage.upload(OBJECT_KEY, new ByteArrayInputStream(data), data.length);

Expand Down