Search in sources :

Example 26 with CommitRequest

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

the class DocumentReferenceTest method createDocument.

@Test
public void createDocument() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.create(SINGLE_FIELD_MAP).get();
    documentReference.create(SINGLE_FIELD_OBJECT).get();
    CommitRequest expectedCommit = commit(create(SINGLE_FIELD_PROTO));
    List<CommitRequest> commitRequests = commitCapture.getAllValues();
    assertCommitEquals(expectedCommit, commitRequests.get(0));
    assertCommitEquals(expectedCommit, commitRequests.get(1));
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 27 with CommitRequest

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

the class DocumentReferenceTest method updateDocument.

@Test
public void updateDocument() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.update(SINGLE_FIELD_MAP);
    documentReference.update("foo", "bar").get();
    CommitRequest expectedCommit = commit(update(SINGLE_FIELD_PROTO, Collections.singletonList("foo")));
    for (CommitRequest request : commitCapture.getAllValues()) {
        assertCommitEquals(expectedCommit, request);
    }
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 28 with CommitRequest

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

the class DocumentReferenceTest method updateDocumentWithTwoFields.

@Test
public void updateDocumentWithTwoFields() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.update("a", "b", "c", "d").get();
    CommitRequest expectedCommit = commit(update(map("a", Value.newBuilder().setStringValue("b").build(), "c", Value.newBuilder().setStringValue("d").build()), Arrays.asList("a", "c")));
    assertCommitEquals(expectedCommit, commitCapture.getValue());
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 29 with CommitRequest

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

the class WriteBatchTest method createDocumentWithValue.

@Test
public void createDocumentWithValue() throws Exception {
    doReturn(commitResponse(2, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    batch.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO).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 30 with CommitRequest

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

the class FirestoreClientTest method commitTest.

@Test
public void commitTest() throws Exception {
    CommitResponse expectedResponse = CommitResponse.newBuilder().addAllWriteResults(new ArrayList<WriteResult>()).setCommitTime(Timestamp.newBuilder().build()).build();
    mockFirestore.addResponse(expectedResponse);
    String database = "database1789464955";
    List<Write> writes = new ArrayList<>();
    CommitResponse actualResponse = client.commit(database, writes);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockFirestore.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
    Assert.assertEquals(database, actualRequest.getDatabase());
    Assert.assertEquals(writes, actualRequest.getWritesList());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Write(com.google.firestore.v1.Write) CommitRequest(com.google.firestore.v1.CommitRequest) WriteResult(com.google.firestore.v1.WriteResult) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) ByteString(com.google.protobuf.ByteString) 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