Search in sources :

Example 86 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-firestore by googleapis.

the class WriteBatchTest method setDocumentWithValue.

@Test
public void setDocumentWithValue() throws Exception {
    doReturn(commitResponse(4, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    batch.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO).set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT).set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO, SetOptions.merge()).set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT, SetOptions.merge());
    List<Write> writes = new ArrayList<>();
    writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
    writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
    writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));
    writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));
    assertEquals(4, batch.getMutationsSize());
    List<WriteResult> writeResults = batch.commit().get();
    for (int i = 0; i < writeResults.size(); ++i) {
        assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
    }
    CommitRequest commitRequest = commitCapture.getValue();
    assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) Write(com.google.firestore.v1.Write) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 87 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-firestore by googleapis.

the class WriteBatchTest method createDocumentWithFloat.

@Test
public void createDocumentWithFloat() throws Exception {
    doReturn(commitResponse(1, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    batch.create(documentReference, LocalFirestoreHelper.SINGLE_FLOAT_MAP);
    assertEquals(1, batch.getMutationsSize());
    List<WriteResult> writeResults = batch.commit().get();
    List<Write> writes = new ArrayList<>();
    for (int i = 0; i < writeResults.size(); ++i) {
        assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
        writes.add(create(LocalFirestoreHelper.SINGLE_FLOAT_PROTO));
    }
    CommitRequest commitRequest = commitCapture.getValue();
    assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) Write(com.google.firestore.v1.Write) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 88 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-firestore by googleapis.

the class WriteBatchTest method setDocument.

@Test
public void setDocument() throws Exception {
    doReturn(commitResponse(4, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    batch.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP).set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT).set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP, SetOptions.merge()).set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT, SetOptions.merge());
    List<Write> writes = new ArrayList<>();
    writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
    writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
    writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));
    writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));
    assertEquals(4, batch.getMutationsSize());
    List<WriteResult> writeResults = batch.commit().get();
    for (int i = 0; i < writeResults.size(); ++i) {
        assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
    }
    CommitRequest commitRequest = commitCapture.getValue();
    assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) Write(com.google.firestore.v1.Write) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 89 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-firestore by googleapis.

the class WriteBatchTest method createDocument.

@Test
public void createDocument() throws Exception {
    doReturn(commitResponse(2, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    batch.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP).create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT);
    assertEquals(2, batch.getMutationsSize());
    List<WriteResult> writeResults = batch.commit().get();
    List<Write> writes = new ArrayList<>();
    for (int i = 0; i < writeResults.size(); ++i) {
        assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
        writes.add(create(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
    }
    CommitRequest commitRequest = commitCapture.getValue();
    assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) Write(com.google.firestore.v1.Write) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 90 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project java-firestore by googleapis.

the class WriteBatchTest method updateDocument.

@Test
public void updateDocument() throws Exception {
    doReturn(commitResponse(4, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    List<com.google.firestore.v1.Precondition> preconditions = Arrays.asList(com.google.firestore.v1.Precondition.newBuilder().setExists(true).build(), com.google.firestore.v1.Precondition.newBuilder().setExists(true).build(), com.google.firestore.v1.Precondition.newBuilder().setUpdateTime(com.google.protobuf.Timestamp.getDefaultInstance()).build(), com.google.firestore.v1.Precondition.newBuilder().setUpdateTime(com.google.protobuf.Timestamp.getDefaultInstance()).build());
    Precondition updateTime = Precondition.updatedAt(Timestamp.ofTimeSecondsAndNanos(0, 0));
    batch.update(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP);
    batch.update(documentReference, "foo", "bar");
    batch.update(documentReference, updateTime, "foo", "bar");
    batch.update(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP, updateTime);
    assertEquals(4, batch.getMutationsSize());
    List<WriteResult> writeResults = batch.commit().get();
    List<Write> writes = new ArrayList<>();
    for (int i = 0; i < writeResults.size(); ++i) {
        assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
        writes.add(update(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Collections.singletonList("foo"), preconditions.get(i)));
    }
    CommitRequest commitRequest = commitCapture.getValue();
    assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) Write(com.google.firestore.v1.Write) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)85 CommitRequest (com.google.spanner.v1.CommitRequest)47 CommitRequest (com.google.firestore.v1.CommitRequest)40 CommitResponse (com.google.firestore.v1.CommitResponse)40 ArrayList (java.util.ArrayList)26 Connection (java.sql.Connection)23 ByteString (com.google.protobuf.ByteString)14 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)12 SQLException (java.sql.SQLException)12 Statement (java.sql.Statement)12 CopyManager (org.postgresql.copy.CopyManager)11 BaseConnection (org.postgresql.core.BaseConnection)11 ExecuteBatchDmlRequest (com.google.spanner.v1.ExecuteBatchDmlRequest)10 ArrayValue (com.google.firestore.v1.ArrayValue)9 MapValue (com.google.firestore.v1.MapValue)9 Value (com.google.firestore.v1.Value)9 Write (com.google.firestore.v1.Write)9 StringReader (java.io.StringReader)9 HashMap (java.util.HashMap)9 AbstractMessage (com.google.protobuf.AbstractMessage)8