Skip to content

Commit 1406e89

Browse files
committed
---
yaml --- r: 115 b: refs/heads/master c: 705c1f0 h: refs/heads/master i: 113: eae8671 111: cd4e620 v: v3
1 parent 1aadda7 commit 1406e89

10 files changed

Lines changed: 55 additions & 20 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: ff7aebf4a70430896aaaaf9f3cc41e226cb3c7d2
2+
refs/heads/master: 705c1f04eb3c5d2cb27e421a374b693ac0955305

trunk/src/main/java/com/google/gcloud/datastore/BaseDatastoreBatchWriter.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5-
* in compliance with the License. You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
67
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
89
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the License
10-
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11-
* or implied. See the License for the specific language governing permissions and limitations under
12-
* the License.
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1315
*/
1416

1517
package com.google.gcloud.datastore;
1618

1719
import com.google.api.services.datastore.DatastoreV1;
1820

19-
import java.util.*;
21+
import java.util.LinkedHashMap;
22+
import java.util.LinkedHashSet;
23+
import java.util.LinkedList;
24+
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Set;
2027

2128
/**
2229
* Base class for DatastoreBatchWriter.

trunk/src/main/java/com/google/gcloud/datastore/BatchImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/*
22
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5-
* in compliance with the License. You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
67
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
89
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the License
10-
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11-
* or implied. See the License for the specific language governing permissions and limitations under
12-
* the License.
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1315
*/
1416

1517
package com.google.gcloud.datastore;

trunk/src/main/java/com/google/gcloud/datastore/Cursor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
import com.google.api.services.datastore.DatastoreV1.Value;
2424
import com.google.common.base.MoreObjects;
2525
import com.google.common.base.MoreObjects.ToStringHelper;
26+
import com.google.common.base.Preconditions;
2627
import com.google.protobuf.ByteString;
2728
import com.google.protobuf.InvalidProtocolBufferException;
29+
import com.google.protobuf.TextFormat;
30+
import com.google.protobuf.TextFormat.ParseException;
2831

2932
import java.io.UnsupportedEncodingException;
3033
import java.net.URLDecoder;
@@ -41,6 +44,7 @@ public final class Cursor extends Serializable<DatastoreV1.Value> {
4144
private final transient ByteString byteString;
4245

4346
Cursor(ByteString byteString) {
47+
Preconditions.checkArgument(byteString.isValidUtf8(), "content is not a valid UTF-8");
4448
this.byteString = byteString;
4549
}
4650

@@ -73,7 +77,7 @@ ByteString byteString() {
7377
*/
7478
public String toUrlSafe() {
7579
try {
76-
return URLEncoder.encode(toPb().toString(), UTF_8.name());
80+
return URLEncoder.encode(TextFormat.printToString(toPb()), UTF_8.name());
7781
} catch (UnsupportedEncodingException e) {
7882
throw new IllegalStateException("Unexpected encoding exception", e);
7983
}
@@ -85,8 +89,10 @@ public String toUrlSafe() {
8589
public static Cursor fromUrlSafe(String urlSafe) {
8690
try {
8791
String utf8Str = URLDecoder.decode(urlSafe, UTF_8.name());
88-
return fromPb(DatastoreV1.Value.parseFrom(ByteString.copyFromUtf8(utf8Str)));
89-
} catch (UnsupportedEncodingException | InvalidProtocolBufferException e) {
92+
DatastoreV1.Value.Builder builder = DatastoreV1.Value.newBuilder();
93+
TextFormat.merge(utf8Str, builder);
94+
return fromPb(builder.build());
95+
} catch (UnsupportedEncodingException | ParseException e) {
9096
throw new IllegalStateException("Unexpected decoding exception", e);
9197
}
9298
}

trunk/src/site/site.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
<!--
2+
~ Copyright 2015 Google Inc. All Rights Reserved.
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
117
<project xmlns="http://maven.apache.org/DECORATION/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
218
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.1.0 http://maven.apache.org/xsd/decoration-1.1.0.xsd"
319
name="GCloud Java">

trunk/src/test/java/com/google/gcloud/datastore/BaseDatastoreBatchWriterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* * Copyright 2015 Google Inc. All Rights Reserved. * * 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 com.google.gcloud.datastore;import static org.junit.Assert.assertEquals;import com.google.api.services.datastore.DatastoreV1;import org.junit.Before;import org.junit.Test;public class BaseDatastoreBatchWriterTest { private static final Key KEY1 = Key.builder("dataset1", "kind1", "name1").build(); private static final Key KEY2 = Key.builder("dataset1", "kind1", 1).build(); private static final Key KEY3 = Key.builder("dataset1", "kind1", 2).build(); private static final PartialKey PARTIAL_KEY = PartialKey.builder("dataset1", "kind1").build(); private static final Entity ENTITY1 = Entity.builder(KEY1).build(); private static final Entity ENTITY2 = Entity.builder(KEY2).set("bak", true).build(); private static final Entity ENTITY3 = Entity.builder(KEY3).set("bak", true).build(); private static final PartialEntity PARTIAL_ENTITY_1 = Entity.builder(PARTIAL_KEY).build(); private static final PartialEntity PARTIAL_ENTITY_2 = PartialEntity.builder(PARTIAL_KEY).set("name", "dan").build(); private DatastoreBatchWriter batchWriter; private class DatastoreBatchWriter extends BaseDatastoreBatchWriter { protected DatastoreBatchWriter() { super("test"); } } @Before public void setUp() { batchWriter = new DatastoreBatchWriter(); } @Test public void testAdd() throws Exception { DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addInsert(ENTITY1.toPb()) .addInsert(ENTITY2.toPb()) .addInsert(ENTITY3.toPb()) .build(); batchWriter.add(ENTITY1, ENTITY2); batchWriter.add(ENTITY3); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testAddAfterDelete() throws Exception { DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpsert(ENTITY1.toPb()) .build(); batchWriter.delete(KEY1); batchWriter.add(ENTITY1); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test(expected = DatastoreServiceException.class) public void testAddDuplicate() throws Exception { batchWriter.add(ENTITY1); batchWriter.add(ENTITY1); } @Test(expected = DatastoreServiceException.class) public void testAddAfterPut() throws Exception { batchWriter.put(ENTITY1); batchWriter.add(ENTITY1); } @Test(expected = DatastoreServiceException.class) public void testAddAfterUpdate() throws Exception { batchWriter.update(ENTITY1); batchWriter.add(ENTITY1); } @Test(expected = DatastoreServiceException.class) public void testAddWhenNotActive() throws Exception { batchWriter.deactivate(); batchWriter.add(ENTITY1); } @Test public void testAddAutoId() throws Exception { DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addInsert(ENTITY1.toPb()) .addInsertAutoId(PARTIAL_ENTITY_1.toPb()) .addInsertAutoId(PARTIAL_ENTITY_2.toPb()) .build(); batchWriter.add(ENTITY1, PARTIAL_ENTITY_1); batchWriter.add(PARTIAL_ENTITY_2); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test(expected = DatastoreServiceException.class) public void testAddAutoIdWhenNotActive() throws Exception { batchWriter.deactivate(); batchWriter.add(PARTIAL_ENTITY_1); } @Test public void testUpdate() throws Exception { DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpdate(ENTITY1.toPb()) .addUpdate(ENTITY2.toPb()) .addUpdate(ENTITY3.toPb()) .build(); batchWriter.update(ENTITY1, ENTITY2); batchWriter.update(ENTITY3); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testUpdateAfterUpdate() throws Exception { Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpdate(entity.toPb()) .build(); batchWriter.update(ENTITY1); batchWriter.update(entity); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testUpdateAfterAdd() throws Exception { Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpsert(entity.toPb()) .build(); batchWriter.add(ENTITY1); batchWriter.update(entity); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testUpdateAfterPut() throws Exception { Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpsert(entity.toPb()) .build(); batchWriter.put(ENTITY1); batchWriter.update(entity); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test(expected = DatastoreServiceException.class) public void testUpdateAfterDelete() throws Exception { batchWriter.delete(KEY1); batchWriter.update(ENTITY1, ENTITY2); } @Test(expected = DatastoreServiceException.class) public void testUpdateWhenNotActive() throws Exception { batchWriter.deactivate(); batchWriter.update(ENTITY1); } @Test public void testPut() throws Exception { DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpsert(ENTITY1.toPb()) .addUpsert(ENTITY2.toPb()) .addUpsert(ENTITY3.toPb()) .build(); batchWriter.put(ENTITY1, ENTITY2); batchWriter.put(ENTITY3); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testPutAfterPut() throws Exception { Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpsert(entity.toPb()) .build(); batchWriter.put(ENTITY1); batchWriter.put(entity); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testPutAfterAdd() throws Exception { Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpsert(entity.toPb()) .build(); batchWriter.add(ENTITY1); batchWriter.put(entity); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testPutAfterUpdate() throws Exception { Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpsert(entity.toPb()) .build(); batchWriter.update(ENTITY1); batchWriter.put(entity); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testPutAfterDelete() throws Exception { Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addUpsert(entity.toPb()) .build(); batchWriter.delete(KEY1); batchWriter.put(entity); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test(expected = DatastoreServiceException.class) public void testPutWhenNotActive() throws Exception { batchWriter.deactivate(); batchWriter.put(ENTITY1); } @Test public void testDelete() throws Exception { DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addDelete(KEY1.toPb()) .addDelete(KEY2.toPb()) .addDelete(KEY3.toPb()) .build(); batchWriter.delete(KEY1, KEY2); batchWriter.delete(KEY3); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testDeleteAfterAdd() throws Exception { DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addInsertAutoId(PARTIAL_ENTITY_1.toPb()) .addDelete(KEY1.toPb()) .build(); batchWriter.add(ENTITY1); batchWriter.add(PARTIAL_ENTITY_1); batchWriter.delete(KEY1); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testDeleteAfterUpdate() throws Exception { DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addDelete(KEY1.toPb()) .build(); batchWriter.update(ENTITY1); batchWriter.delete(KEY1); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test public void testDeleteAfterPut() throws Exception { DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder() .addDelete(KEY1.toPb()) .build(); batchWriter.put(ENTITY1); batchWriter.delete(KEY1); assertEquals(pb, batchWriter.toMutationPb().build()); } @Test(expected = DatastoreServiceException.class) public void testDeleteWhenNotActive() throws Exception { batchWriter.deactivate(); batchWriter.delete(KEY1); }}

0 commit comments

Comments
 (0)