Search in sources :

Example 6 with CompiledCursor

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);
}
Also used : Query(com.google.apphosting.datastore.DatastoreV3Pb.Query) ByteArrayInputStream(java.io.ByteArrayInputStream) CompiledCursor(com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CompiledCursor(com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

CompiledCursor (com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor)6 Test (org.junit.Test)4 Query (com.google.apphosting.datastore.DatastoreV3Pb.Query)2 IndexPosition (com.google.storage.onestore.v3.OnestoreEntity.IndexPosition)1 IndexPostfix (com.google.storage.onestore.v3.OnestoreEntity.IndexPostfix)1 Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Before (org.junit.Before)1