diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/GlobalSecondaryIndex.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/GlobalSecondaryIndex.java index 5cd7e1e268..ca145d6ac8 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/GlobalSecondaryIndex.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/GlobalSecondaryIndex.java @@ -64,6 +64,7 @@ public class GlobalSecondaryIndex { public long getIndexSizeBytes() { return indexSizeBytes; } public void setIndexSizeBytes(long indexSizeBytes) { this.indexSizeBytes = indexSizeBytes; } + @JsonIgnore public String getPartitionKeyName() { return keySchema.stream() .filter(k -> "HASH".equals(k.getKeyType())) @@ -72,6 +73,7 @@ public class GlobalSecondaryIndex { .orElseThrow(); } + @JsonIgnore public String getSortKeyName() { return keySchema.stream() .filter(k -> "RANGE".equals(k.getKeyType())) diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/LocalSecondaryIndex.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/LocalSecondaryIndex.java index d9d71483ef..7f8888717c 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/LocalSecondaryIndex.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/LocalSecondaryIndex.java @@ -63,6 +63,7 @@ public class LocalSecondaryIndex { public long getItemCount() { return itemCount; } public void setItemCount(long itemCount) { this.itemCount = itemCount; } + @JsonIgnore public String getPartitionKeyName() { return keySchema.stream() .filter(k -> "HASH".equals(k.getKeyType())) @@ -71,6 +72,7 @@ public class LocalSecondaryIndex { .orElseThrow(); } + @JsonIgnore public String getSortKeyName() { return keySchema.stream() .filter(k -> "RANGE".equals(k.getKeyType())) diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/TableDefinition.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/TableDefinition.java index c60e0ab4d0..e8e95bc11f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/TableDefinition.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/model/TableDefinition.java @@ -207,6 +207,7 @@ public class TableDefinition { public Integer getOnDemandMaxWriteRequestUnits() { return onDemandMaxWriteRequestUnits; } public void setOnDemandMaxWriteRequestUnits(Integer v) { this.onDemandMaxWriteRequestUnits = v; } + @JsonIgnore public String getPartitionKeyName() { return keySchema.stream() .filter(k -> "HASH".equals(k.getKeyType())) @@ -216,6 +217,7 @@ public class TableDefinition { } /** Returns the sort key attribute name, or null if none. */ + @JsonIgnore public String getSortKeyName() { return keySchema.stream() .filter(k -> "RANGE".equals(k.getKeyType())) diff --git a/src/test/java/io/github/hectorvent/floci/core/storage/HybridStorageTest.java b/src/test/java/io/github/hectorvent/floci/core/storage/HybridStorageTest.java index c82c62fa35..0108e67eb3 100644 --- a/src/test/java/io/github/hectorvent/floci/core/storage/HybridStorageTest.java +++ b/src/test/java/io/github/hectorvent/floci/core/storage/HybridStorageTest.java @@ -1,12 +1,17 @@ package io.github.hectorvent.floci.core.storage; import com.fasterxml.jackson.core.type.TypeReference; +import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition; +import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement; +import io.github.hectorvent.floci.services.dynamodb.model.LocalSecondaryIndex; +import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import java.nio.file.Path; +import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assertions.*; @@ -50,6 +55,30 @@ class HybridStorageTest { store2.shutdown(); } + @Test + void dynamoTableWithLocalSecondaryIndexSurvivesRestart() { + Path filePath = tempDir.resolve("dynamodb-tables.json"); + TypeReference> type = new TypeReference<>() {}; + var table = new TableDefinition( + "ConfigTable", + List.of(new KeySchemaElement("pk", "HASH"), new KeySchemaElement("sk", "RANGE")), + List.of(new AttributeDefinition("pk", "S"), new AttributeDefinition("sk", "S"), + new AttributeDefinition("lsiSk", "S"))); + table.setLocalSecondaryIndexes(List.of(new LocalSecondaryIndex( + "lsi", List.of(new KeySchemaElement("pk", "HASH"), + new KeySchemaElement("lsiSk", "RANGE")), null, "ALL"))); + + var store1 = new HybridStorage(filePath, type, 60000); + store1.put("000000000000/us-east-1::ConfigTable", table); + store1.shutdown(); + + var store2 = new HybridStorage(filePath, type, 60000); + store2.load(); + TableDefinition restored = store2.get("000000000000/us-east-1::ConfigTable").orElseThrow(); + assertEquals("lsiSk", restored.getLocalSecondaryIndexes().getFirst().getSortKeyName()); + store2.shutdown(); + } + @Test void deleteRemovesFromMemory() { storage.put("key1", "value1");