Skip to content

Commit 6ad13c5

Browse files
authored
---
yaml --- r: 5497 b: refs/heads/master c: c68743c h: refs/heads/master i: 5495: 2d5f78f
1 parent 37b4c75 commit 6ad13c5

4 files changed

Lines changed: 35 additions & 27 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 50856d69fcaaa53689d9425d9754cb7bbfbfb239
2+
refs/heads/master: c68743cecffabe9181c8ab191a356f56bfb8fac1
33
refs/heads/travis: dae77e558b884bc1b165155482d76c8e40b0fca4
44
refs/heads/gh-pages: 4936f6d1c43be1ab76229d2743bae07f4b4124b3
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,18 @@ public Key allocateId(IncompleteKey key) {
105105
return DatastoreHelper.allocateId(this, key);
106106
}
107107

108+
private boolean verifyIncompleteKeyType(IncompleteKey... keys) {
109+
for (IncompleteKey key : keys) {
110+
if (key instanceof Key) {
111+
return false;
112+
}
113+
}
114+
return true;
115+
}
116+
108117
@Override
109118
public List<Key> allocateId(IncompleteKey... keys) {
119+
Preconditions.checkArgument(verifyIncompleteKeyType(keys), "keys must be IncompleteKey instances");
110120
if (keys.length == 0) {
111121
return Collections.emptyList();
112122
}
@@ -123,7 +133,7 @@ public List<Key> allocateId(IncompleteKey... keys) {
123133
return keyList.build();
124134
}
125135

126-
com.google.datastore.v1.AllocateIdsResponse allocateIds(
136+
private com.google.datastore.v1.AllocateIdsResponse allocateIds(
127137
final com.google.datastore.v1.AllocateIdsRequest requestPb) {
128138
try {
129139
return RetryHelper.runWithRetries(

trunk/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,12 @@ public void testAllocateId() {
688688
assertNotEquals(key1, key2);
689689
assertEquals(Key.newBuilder(pk1, key2.getId()).build(), key2);
690690

691-
Key key3 = datastore.allocateId(key1);
692-
assertNotEquals(key1, key3);
693-
assertEquals(Key.newBuilder(pk1, key3.getId()).build(), key3);
691+
try {
692+
datastore.allocateId(key1);
693+
fail("Expecting a failure");
694+
} catch (IllegalArgumentException expected) {
695+
assertEquals(expected.getMessage(), "keys must be IncompleteKey instances");
696+
}
694697
}
695698

696699
@Test
@@ -700,16 +703,20 @@ public void testAllocateIdArray() {
700703
IncompleteKey incompleteKey2 =
701704
keyFactory.setKind(KIND2).addAncestor(PathElement.of(KIND1, 10)).newKey();
702705
Key key3 = keyFactory.newKey("name");
703-
Key key4 = keyFactory.newKey(1);
704-
List<Key> result =
705-
datastore.allocateId(incompleteKey1, incompleteKey2, key3, key4, incompleteKey1, key3);
706-
assertEquals(6, result.size());
707-
assertEquals(Key.newBuilder(incompleteKey1, result.get(0).getId()).build(), result.get(0));
708-
assertEquals(Key.newBuilder(incompleteKey1, result.get(4).getId()).build(), result.get(4));
709-
assertEquals(Key.newBuilder(incompleteKey2, result.get(1).getId()).build(), result.get(1));
710-
assertEquals(Key.newBuilder(key3).setId(result.get(2).getId()).build(), result.get(2));
711-
assertEquals(Key.newBuilder(key3).setId(result.get(5).getId()).build(), result.get(5));
712-
assertEquals(Key.newBuilder(key4).setId(result.get(3).getId()).build(), result.get(3));
706+
List<Key> result1 =
707+
datastore.allocateId(incompleteKey1, incompleteKey2, incompleteKey1);
708+
assertEquals(3, result1.size());
709+
assertEquals(Key.newBuilder(incompleteKey1, result1.get(0).getId()).build(), result1.get(0));
710+
assertEquals(Key.newBuilder(incompleteKey1, result1.get(2).getId()).build(), result1.get(2));
711+
assertEquals(Key.newBuilder(incompleteKey2, result1.get(1).getId()).build(), result1.get(1));
712+
713+
try {
714+
datastore.allocateId(incompleteKey1, incompleteKey2, key3);
715+
fail("expecting a failure");
716+
} catch(IllegalArgumentException expected) {
717+
assertEquals(expected.getMessage(), "keys must be IncompleteKey instances");
718+
719+
}
713720
}
714721

715722
@Test

trunk/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,6 @@ public void testAllocateId() {
517517
Key key2 = DATASTORE.allocateId(pk1);
518518
assertNotEquals(key1, key2);
519519
assertEquals(Key.newBuilder(pk1, key2.getId()).build(), key2);
520-
521-
Key key3 = DATASTORE.allocateId(key1);
522-
assertNotEquals(key1, key3);
523-
assertEquals(Key.newBuilder(pk1, key3.getId()).build(), key3);
524520
}
525521

526522
@Test
@@ -529,17 +525,12 @@ public void testAllocateIdArray() {
529525
IncompleteKey incompleteKey1 = keyFactory.newKey();
530526
IncompleteKey incompleteKey2 =
531527
keyFactory.setKind(KIND2).addAncestors(PathElement.of(KIND1, 10)).newKey();
532-
Key key3 = keyFactory.newKey("name");
533-
Key key4 = keyFactory.newKey(1);
534528
List<Key> result =
535-
DATASTORE.allocateId(incompleteKey1, incompleteKey2, key3, key4, incompleteKey1, key3);
536-
assertEquals(6, result.size());
529+
DATASTORE.allocateId(incompleteKey1, incompleteKey2, incompleteKey1);
530+
assertEquals(3, result.size());
537531
assertEquals(Key.newBuilder(incompleteKey1, result.get(0).getId()).build(), result.get(0));
538-
assertEquals(Key.newBuilder(incompleteKey1, result.get(4).getId()).build(), result.get(4));
532+
assertEquals(Key.newBuilder(incompleteKey1, result.get(2).getId()).build(), result.get(2));
539533
assertEquals(Key.newBuilder(incompleteKey2, result.get(1).getId()).build(), result.get(1));
540-
assertEquals(Key.newBuilder(key3).setId(result.get(2).getId()).build(), result.get(2));
541-
assertEquals(Key.newBuilder(key3).setId(result.get(5).getId()).build(), result.get(5));
542-
assertEquals(Key.newBuilder(key4).setId(result.get(3).getId()).build(), result.get(3));
543534
}
544535

545536
@Test

0 commit comments

Comments
 (0)