-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix failing test cases for proto1 -> proto2 migration #291
Changes from 11 commits
556f908
9c2191f
a1d5091
5f2586c
82c3b85
a31833f
563e309
4a9e891
e3f4cf2
dc4c3f1
b58db82
2c718f9
6b973ca
d770e51
15c6e84
889e555
1f5fbe1
2d72288
7c1cfc9
0db04e3
1358e17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,7 +209,7 @@ public final class DataTypeTranslator { | |
* @param map A not {@code null} map of all the properties which will be set on {@code proto} | ||
* @param proto A not {@code null} protocol buffer | ||
*/ | ||
public static void addPropertiesToPb(Map<String, ?> map, EntityProto proto) { | ||
public static void addPropertiesToPb(Map<String, ?> map, EntityProto.Builder proto) { | ||
for (Map.Entry<String, ?> entry : map.entrySet()) { | ||
String name = entry.getKey(); | ||
|
||
|
@@ -233,15 +233,15 @@ public static void addPropertiesToPb(Map<String, ?> map, EntityProto proto) { | |
} | ||
} | ||
|
||
/** @see #addPropertiesToPb(Map, EntityProto) */ | ||
/** @see #addPropertiesToPb(Map, EntityProto.Builder) */ | ||
static void addPropertiesToPb(Map<String, ?> map, com.google.datastore.v1.Entity.Builder proto) { | ||
for (Map.Entry<String, ?> entry : map.entrySet()) { | ||
proto.putProperties(entry.getKey(), toV1Value(entry.getValue()).build()); | ||
} | ||
} | ||
|
||
private static void addListPropertyToPb( | ||
EntityProto proto, | ||
EntityProto.Builder proto, | ||
String name, | ||
boolean indexed, | ||
Collection<?> values, | ||
|
@@ -258,11 +258,12 @@ private static void addListPropertyToPb( | |
// If the value is indexed it appears in queries, but distinction between | ||
// null and empty list is lost. | ||
} | ||
property.setValue(PropertyValue.getDefaultInstance()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want help from datastore team there. I am worried about the comment "// Backward compatible behavior", the logic could break moving to proto2... Also, I do not fully understand the logic of setting a default value, while the method arguments above take a collections of values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since value is one of the required fields, not setting it is causing build() to fail |
||
property.getValue(); // Indicate to the proto that we have set this field | ||
if (indexed) { | ||
proto = proto.toBuilder().addProperty(property.build()).build(); | ||
proto.addProperty(property); | ||
} else { | ||
srinjoyray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
proto = proto.toBuilder().addRawProperty(property.build()).build(); | ||
proto.addRawProperty(property); | ||
} | ||
} else { | ||
// Write every element to the PB | ||
|
@@ -291,7 +292,7 @@ private static void addPropertyToPb( | |
boolean indexed, | ||
boolean forceIndexedEmbeddedEntity, | ||
boolean multiple, | ||
EntityProto entity) { | ||
EntityProto.Builder entity) { | ||
Property.Builder property = Property.newBuilder(); | ||
property.setName(name); | ||
property.setMultiple(multiple); | ||
|
@@ -317,9 +318,9 @@ private static void addPropertyToPb( | |
} | ||
} | ||
if (indexed) { | ||
entity = entity.toBuilder().addProperty(property).build(); | ||
entity.addProperty(property); | ||
} else { | ||
entity = entity.toBuilder().addRawProperty(property).build(); | ||
entity.addRawProperty(property); | ||
} | ||
} | ||
|
||
|
@@ -395,6 +396,7 @@ private static Property buildImplicitKeyProperty(EntityProto proto) { | |
PropertyValue.Builder propVal = PropertyValue.newBuilder(); | ||
propVal.setReferenceValue(KeyType.toReferenceValue(proto.getKey())); | ||
keyProp.setValue(propVal.build()); | ||
keyProp.setMultiple(false); | ||
return keyProp.build(); | ||
} | ||
|
||
|
@@ -1137,6 +1139,8 @@ public RawValue getValue(Value propertyValue) { | |
// All possible values except byte[] are already comparable. | ||
if (value2 instanceof byte[]) { | ||
return new ComparableByteArray((byte[]) value2); | ||
} else if (value2 instanceof ByteString) { | ||
return new ComparableByteArray(((ByteString) value2).toByteArray()); | ||
} | ||
return (Comparable<?>) value2; | ||
} | ||
|
@@ -1683,7 +1687,7 @@ public void toV3Value(Object value, PropertyValue.Builder propertyValue) { | |
if (structProp.getKey() != null) { | ||
proto.setKey(KeyTranslator.convertToPb(structProp.getKey())); | ||
} | ||
addPropertiesToPb(structProp.getPropertyMap(), proto.build()); | ||
addPropertiesToPb(structProp.getPropertyMap(), proto); | ||
// TODO: Figure out how to do partial serialization. | ||
propertyValue.setStringValueBytes(proto.build().toByteString()).build(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,23 +130,25 @@ static <T extends Message> Future<T> makeAsyncCall( | |
return new FutureWrapper<byte[], T>(response) { | ||
@Override | ||
protected T wrap(byte[] responseBytes) throws InvalidProtocolBufferException { | ||
T updatedResponseProto = null; | ||
// This null check is mainly for the benefit of unit tests | ||
// (specifically ones using EasyMock, where the default behavior | ||
// is to return null). | ||
if (responseBytes != null && responseProto != null) { | ||
|
||
try { | ||
responseProto.getParserForType().parseFrom(responseBytes); | ||
updatedResponseProto = (T) responseProto.getParserForType().parseFrom(responseBytes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why we need a new variable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am trying to pass the response argument as a builder in this func, then we would not need another variable. But facing a bit of difficulty in handling the other functions which calls this makeAsyncCall method |
||
} | ||
catch(InvalidProtocolBufferException e) { | ||
throw new InvalidProtocolBufferException( | ||
String.format("Invalid %s.%s response", DATASTORE_V3_PACKAGE, method.name())); | ||
} | ||
List<String> initializationErrors = responseProto.findInitializationErrors(); | ||
List<String> initializationErrors = updatedResponseProto.findInitializationErrors(); | ||
if (initializationErrors != null && !initializationErrors.isEmpty()) { | ||
throw new InvalidProtocolBufferException(initializationErrors.toString()); | ||
} | ||
} | ||
return responseProto; | ||
return updatedResponseProto; | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import com.google.apphosting.api.AppEngineInternal; | ||
import com.google.storage.onestore.v3.proto2api.OnestoreEntity; | ||
import com.google.storage.onestore.v3.proto2api.OnestoreEntity.CompositeIndex.State; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
@@ -73,6 +74,7 @@ public static Index.Property convertFromPb(OnestoreEntity.Index.Property propert | |
} | ||
|
||
public static Index convertFromPb(OnestoreEntity.Index index) { | ||
return convertFromPb(OnestoreEntity.CompositeIndex.newBuilder().setId(0).setDefinition(index).build()); | ||
return convertFromPb(OnestoreEntity.CompositeIndex.newBuilder().setId(0).setDefinition(index).setAppId("").setState( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hum, sure an emtpy appId is fine there? Maybe, but not sure! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using the values that are present in the private default constructor |
||
State.WRITE_ONLY).build()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import com.google.storage.onestore.v3.proto2api.OnestoreEntity.Path; | ||
import com.google.storage.onestore.v3.proto2api.OnestoreEntity.Path.Element; | ||
import com.google.storage.onestore.v3.proto2api.OnestoreEntity.Reference; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
|
@@ -71,7 +72,7 @@ public static Reference convertToPb(Key key) { | |
reference.setNameSpace(nameSpace); | ||
} | ||
|
||
Path.Builder path = reference.build().getPath().toBuilder(); | ||
Path.Builder path = reference.getPathBuilder(); | ||
while (key != null) { | ||
Element.Builder pathElement = Element.newBuilder(); | ||
pathElement.setType(key.getKind()); | ||
|
@@ -83,7 +84,13 @@ public static Reference convertToPb(Key key) { | |
path.addElement(pathElement.build()); | ||
key = key.getParent(); | ||
} | ||
Collections.reverse(path.build().getElementList()); | ||
List<Element> elements = new ArrayList<>(path.getElementList()); | ||
Collections.reverse(elements); | ||
Path.Builder reversedPath = Path.newBuilder(); | ||
for(Element element : elements){ | ||
reversedPath.addElement(element); | ||
} | ||
reference.setPath(reversedPath.build()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a setPathBuilder instead? Not sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setPathBuilder is not present |
||
return reference.build(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still not sure we need buildPartial() in api (thinking only in test code, not code we give to customers).
So are you sure these build to buildPartial really solve test faitures?
Maybe we could change some (non public API) to use builders as long as possible, until we really need to build it)