use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project pgadapter by GoogleCloudPlatform.
the class CopyInMockServerTest method testCopyInError.
@Test
public void testCopyInError() throws SQLException {
setupCopyInformationSchemaResults();
mockSpanner.setCommitExecutionTime(SimulatedExecutionTime.ofException(Status.INVALID_ARGUMENT.asRuntimeException()));
try (Connection connection = DriverManager.getConnection(createUrl())) {
CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));
SQLException exception = assertThrows(SQLException.class, () -> copyManager.copyIn("COPY users FROM STDIN;", new StringReader("5\t5\t5\n6\t6\t6\n7\t7\t7\n")));
assertTrue(exception.getMessage().contains("io.grpc.StatusRuntimeException: INVALID_ARGUMENT"));
}
// The server should receive one commit request, but this commit failed in this case.
List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertEquals(1, commitRequests.size());
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project pgadapter by GoogleCloudPlatform.
the class CopyInMockServerTest method testCopyIn.
@Test
public void testCopyIn() throws SQLException, IOException {
setupCopyInformationSchemaResults();
try (Connection connection = DriverManager.getConnection(createUrl())) {
CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));
copyManager.copyIn("COPY users FROM STDIN;", new StringReader("5\t5\t5\n6\t6\t6\n7\t7\t7\n"));
// Verify that we can use the connection for normal queries.
try (ResultSet resultSet = connection.createStatement().executeQuery("SELECT 1")) {
assertTrue(resultSet.next());
assertEquals(1L, resultSet.getLong(1));
assertFalse(resultSet.next());
}
}
List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertEquals(1, commitRequests.size());
CommitRequest commitRequest = commitRequests.get(0);
assertEquals(1, commitRequest.getMutationsCount());
Mutation mutation = commitRequest.getMutations(0);
assertEquals(OperationCase.INSERT, mutation.getOperationCase());
assertEquals(3, mutation.getInsert().getValuesCount());
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project pgadapter by GoogleCloudPlatform.
the class CopyInMockServerTest method testCopyIn_TableNotFound.
@Test
public void testCopyIn_TableNotFound() throws SQLException {
setupCopyInformationSchemaResults(false);
try (Connection connection = DriverManager.getConnection(createUrl())) {
CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));
SQLException exception = assertThrows(SQLException.class, () -> copyManager.copyIn("COPY users FROM STDIN;", new StringReader("5\t5\t5\n")));
assertEquals("ERROR: INVALID_ARGUMENT: Table users is not found in information_schema", exception.getMessage());
// Verify that we can use the connection for normal queries.
try (ResultSet resultSet = connection.createStatement().executeQuery("SELECT 1")) {
assertTrue(resultSet.next());
assertEquals(1L, resultSet.getLong(1));
assertFalse(resultSet.next());
}
}
List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertTrue(commitRequests.isEmpty());
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project pgadapter by GoogleCloudPlatform.
the class CopyInMockServerTest method testCopyIn_Cancel.
@Test
public void testCopyIn_Cancel() throws SQLException {
setupCopyInformationSchemaResults();
byte[] payload = "5\t5\t5\n".getBytes(StandardCharsets.UTF_8);
try (Connection connection = DriverManager.getConnection(createUrl())) {
CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));
CopyIn copyOperation = copyManager.copyIn("COPY users FROM STDIN;");
copyOperation.writeToCopy(payload, 0, payload.length);
copyOperation.cancelCopy();
// Verify that we can use the connection for normal queries.
try (ResultSet resultSet = connection.createStatement().executeQuery("SELECT 1")) {
assertTrue(resultSet.next());
assertEquals(1L, resultSet.getLong(1));
assertFalse(resultSet.next());
}
}
List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertTrue(commitRequests.isEmpty());
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project pgadapter by GoogleCloudPlatform.
the class DdlTransactionModeAutocommitImplicitTest method testMixedBatch.
@Test
public void testMixedBatch() throws SQLException {
String sql = "CREATE TABLE foo (id bigint primary key); INSERT INTO FOO VALUES (1); UPDATE FOO SET BAR=1 WHERE BAZ=2;";
addDdlResponseToSpannerAdmin();
try (Connection connection = DriverManager.getConnection(createUrl())) {
try (Statement statement = connection.createStatement()) {
// Statement#execute(String) returns false if the result was either an update count or there
// was no result. Statement#getUpdateCount() returns 0 if there was no result.
assertFalse(statement.execute(sql));
assertEquals(0, statement.getUpdateCount());
// getMoreResults() returns false as the next result is an update count.
assertFalse(statement.getMoreResults());
assertEquals(1, statement.getUpdateCount());
// getMoreResults() returns false as the next result is an update count.
assertFalse(statement.getMoreResults());
assertEquals(2, statement.getUpdateCount());
// getMoreResults() should now return false. We should also check getUpdateCount() as that
// method should return -1 to indicate that there is also no update count available.
assertFalse(statement.getMoreResults());
assertEquals(-1, statement.getUpdateCount());
}
}
List<UpdateDatabaseDdlRequest> updateDatabaseDdlRequests = mockDatabaseAdmin.getRequests().stream().filter(request -> request instanceof UpdateDatabaseDdlRequest).map(UpdateDatabaseDdlRequest.class::cast).collect(Collectors.toList());
assertEquals(1, updateDatabaseDdlRequests.size());
assertEquals(1, updateDatabaseDdlRequests.get(0).getStatementsCount());
assertEquals("CREATE TABLE foo (id bigint primary key)", updateDatabaseDdlRequests.get(0).getStatements(0));
// Verify that the DML statements were batched together by PgAdapter.
List<ExecuteBatchDmlRequest> requests = mockSpanner.getRequestsOfType(ExecuteBatchDmlRequest.class);
assertEquals(1, requests.size());
ExecuteBatchDmlRequest request = requests.get(0);
assertEquals(2, request.getStatementsCount());
assertEquals(INSERT_STATEMENT.getSql(), request.getStatements(0).getSql());
assertEquals(UPDATE_STATEMENT.getSql(), request.getStatements(1).getSql());
List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertEquals(1, commitRequests.size());
}
Aggregations