Search in sources :

Example 1 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class DatabaseClientImplTest method testTransactionManagerCommitWithPriority.

@Test
public void testTransactionManagerCommitWithPriority() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    TransactionManager manager = client.transactionManager(Options.priority(RpcPriority.HIGH));
    TransactionContext transaction = manager.begin();
    transaction.buffer(Mutation.delete("TEST", KeySet.all()));
    manager.commit();
    List<CommitRequest> requests = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(requests).hasSize(1);
    CommitRequest request = requests.get(0);
    assertNotNull(request.getRequestOptions());
    assertEquals(Priority.PRIORITY_HIGH, request.getRequestOptions().getPriority());
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) Test(org.junit.Test)

Example 2 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class DatabaseClientImplTest method testTransactionManagerCommitWithTag.

@Test
public void testTransactionManagerCommitWithTag() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    TransactionManager manager = client.transactionManager(Options.tag("app=spanner,env=test,action=manager"));
    TransactionContext transaction = manager.begin();
    transaction.buffer(Mutation.delete("TEST", KeySet.all()));
    manager.commit();
    List<CommitRequest> requests = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(requests).hasSize(1);
    CommitRequest request = requests.get(0);
    assertNotNull(request.getRequestOptions());
    assertThat(request.getRequestOptions().getRequestTag()).isEmpty();
    assertThat(request.getRequestOptions().getTransactionTag()).isEqualTo("app=spanner,env=test,action=manager");
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) Test(org.junit.Test)

Example 3 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class DatabaseClientImplTest method testCommitWithPriority.

@Test
public void testCommitWithPriority() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    TransactionRunner runner = client.readWriteTransaction(Options.priority(RpcPriority.HIGH));
    runner.run(transaction -> {
        transaction.buffer(Mutation.delete("TEST", KeySet.all()));
        return null;
    });
    List<CommitRequest> requests = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(requests).hasSize(1);
    CommitRequest request = requests.get(0);
    assertNotNull(request.getRequestOptions());
    assertEquals(Priority.PRIORITY_HIGH, request.getRequestOptions().getPriority());
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) Test(org.junit.Test)

Example 4 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class DatabaseClientImplTest method testWriteAtLeastOnceWithCommitStats.

@Test
public void testWriteAtLeastOnceWithCommitStats() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    CommitResponse response = client.writeAtLeastOnceWithOptions(Collections.singletonList(Mutation.newInsertBuilder("FOO").set("ID").to(1L).set("NAME").to("Bar").build()), Options.commitStats());
    assertNotNull(response);
    assertNotNull(response.getCommitTimestamp());
    assertNotNull(response.getCommitStats());
    List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(commitRequests).hasSize(1);
    CommitRequest commit = commitRequests.get(0);
    assertNotNull(commit.getSingleUseTransaction());
    assertTrue(commit.getSingleUseTransaction().hasReadWrite());
    assertNotNull(commit.getRequestOptions());
    assertEquals(Priority.PRIORITY_UNSPECIFIED, commit.getRequestOptions().getPriority());
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) Test(org.junit.Test)

Example 5 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class DatabaseClientImplTest method testWriteWithOptions.

@Test
public void testWriteWithOptions() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    client.writeWithOptions(Collections.singletonList(Mutation.newInsertBuilder("FOO").set("ID").to(1L).set("NAME").to("Bar").build()), Options.priority(RpcPriority.HIGH));
    List<CommitRequest> commits = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(commits).hasSize(1);
    CommitRequest commit = commits.get(0);
    assertNotNull(commit.getRequestOptions());
    assertEquals(Priority.PRIORITY_HIGH, commit.getRequestOptions().getPriority());
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) 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