From b09a7257b65ba7c005c1118da43b2e483c48a307 Mon Sep 17 00:00:00 2001 From: detmerl Date: Fri, 23 Aug 2024 13:29:10 -0400 Subject: [PATCH 1/2] fix: need to also send database ID when migrating keys from ancestor to child --- .../data/datastore/core/util/KeyUtil.java | 1 + .../data/datastore/core/util/KeyUtilTest.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/spring-cloud-gcp-data-datastore/src/main/java/com/google/cloud/spring/data/datastore/core/util/KeyUtil.java b/spring-cloud-gcp-data-datastore/src/main/java/com/google/cloud/spring/data/datastore/core/util/KeyUtil.java index 9b8da5034b..8236b041ec 100644 --- a/spring-cloud-gcp-data-datastore/src/main/java/com/google/cloud/spring/data/datastore/core/util/KeyUtil.java +++ b/spring-cloud-gcp-data-datastore/src/main/java/com/google/cloud/spring/data/datastore/core/util/KeyUtil.java @@ -46,6 +46,7 @@ public static Key getKeyWithoutAncestors(Key entityKey) { Key.newBuilder(entityKey.getProjectId(), entityKey.getKind(), entityKey.getId()); } ancestorLookupKey.setNamespace(entityKey.getNamespace()); + ancestorLookupKey.setDatabaseId(entityKey.getDatabaseId()); return ancestorLookupKey.build(); } diff --git a/spring-cloud-gcp-data-datastore/src/test/java/com/google/cloud/spring/data/datastore/core/util/KeyUtilTest.java b/spring-cloud-gcp-data-datastore/src/test/java/com/google/cloud/spring/data/datastore/core/util/KeyUtilTest.java index 964e1340c0..424db33cc3 100644 --- a/spring-cloud-gcp-data-datastore/src/test/java/com/google/cloud/spring/data/datastore/core/util/KeyUtilTest.java +++ b/spring-cloud-gcp-data-datastore/src/test/java/com/google/cloud/spring/data/datastore/core/util/KeyUtilTest.java @@ -47,4 +47,28 @@ void testRemoveAncestors_IdKeys() { Key processedKey = KeyUtil.getKeyWithoutAncestors(idKey); assertThat(processedKey.getAncestors()).isEmpty(); } + + @Test + void testAncestorKeys_containsAllDataStoreMetaData() { + String projectId = "project-id"; + String kind = "kind"; + Long id = 13L; + String databaseId = "database-id"; + String namespace = "namespace"; + + Key idKey = + Key.newBuilder(projectId, kind, id, databaseId).setNamespace(namespace) + .addAncestor(PathElement.of("person", 22L)) + .addAncestor(PathElement.of("person", 18L)) + .build(); + + Key processedKey = KeyUtil.getKeyWithoutAncestors(idKey); + + assertThat(processedKey.getAncestors()).isEmpty(); + assertThat(processedKey.getId()).isEqualTo(id); + assertThat(processedKey.getKind()).isEqualTo(kind); + assertThat(processedKey.getDatabaseId()).isEqualTo(databaseId); + assertThat(processedKey.getNamespace()).isEqualTo(namespace); + assertThat(processedKey.getProjectId()).isEqualTo(projectId); + } } From b23849259c73aeb3b87471b4bc5156fbf7d16e7e Mon Sep 17 00:00:00 2001 From: detmerl Date: Fri, 23 Aug 2024 13:34:18 -0400 Subject: [PATCH 2/2] lint fix --- .../spring/data/datastore/core/util/KeyUtilTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-cloud-gcp-data-datastore/src/test/java/com/google/cloud/spring/data/datastore/core/util/KeyUtilTest.java b/spring-cloud-gcp-data-datastore/src/test/java/com/google/cloud/spring/data/datastore/core/util/KeyUtilTest.java index 424db33cc3..d851de8f99 100644 --- a/spring-cloud-gcp-data-datastore/src/test/java/com/google/cloud/spring/data/datastore/core/util/KeyUtilTest.java +++ b/spring-cloud-gcp-data-datastore/src/test/java/com/google/cloud/spring/data/datastore/core/util/KeyUtilTest.java @@ -57,10 +57,11 @@ void testAncestorKeys_containsAllDataStoreMetaData() { String namespace = "namespace"; Key idKey = - Key.newBuilder(projectId, kind, id, databaseId).setNamespace(namespace) - .addAncestor(PathElement.of("person", 22L)) - .addAncestor(PathElement.of("person", 18L)) - .build(); + Key.newBuilder(projectId, kind, id, databaseId) + .setNamespace(namespace) + .addAncestor(PathElement.of("person", 22L)) + .addAncestor(PathElement.of("person", 18L)) + .build(); Key processedKey = KeyUtil.getKeyWithoutAncestors(idKey);