use of com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor in project appengine-java-standard by GoogleCloudPlatform.
the class CursorTest method testSerialization.
@Test
public void testSerialization() throws Exception {
CompiledCursor compiledCursor = new CompiledCursor();
CompiledCursor.Position position = compiledCursor.getMutablePosition();
position.setStartKey("Hello World");
position.setStartInclusive(true);
Cursor original = toCursor(compiledCursor);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(original);
byte[] bytes = baos.toByteArray();
ObjectInputStream iis = new ObjectInputStream(new ByteArrayInputStream(bytes));
Cursor readCursor = (Cursor) iis.readObject();
assertThat(readCursor).isNotSameInstanceAs(original);
assertThat(readCursor).isEqualTo(original);
Query query = new Query();
query.setOffset(3);
query.setCompiledCursor(toPb(readCursor));
assertThat(query.getCompiledCursor()).isEqualTo(compiledCursor);
assertThat(query.getOffset()).isEqualTo(3);
}
Aggregations