use of com.google.cloud.spanner.pgadapter.wireprotocol.ControlMessage.PreparedType in project pgadapter by GoogleCloudPlatform.
the class ProtocolTest method testCloseStatementMessage.
@Test
public void testCloseStatementMessage() throws Exception {
byte[] messageMetadata = { 'C' };
byte[] statementType = { 'S' };
String statementName = "some statement\0";
byte[] length = intToBytes(4 + statementType.length + statementName.length());
byte[] value = Bytes.concat(messageMetadata, length, statementType, statementName.getBytes());
String expectedStatementName = "some statement";
PreparedType expectedType = PreparedType.Statement;
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(value));
ByteArrayOutputStream result = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(result);
when(connectionHandler.getStatement(anyString())).thenReturn(intermediatePortalStatement);
when(connectionHandler.getConnectionMetadata()).thenReturn(connectionMetadata);
when(connectionMetadata.getInputStream()).thenReturn(inputStream);
when(connectionMetadata.getOutputStream()).thenReturn(outputStream);
WireMessage message = ControlMessage.create(connectionHandler);
assertEquals(CloseMessage.class, message.getClass());
assertEquals(expectedStatementName, ((CloseMessage) message).getName());
assertEquals(expectedType, ((CloseMessage) message).getType());
verify(connectionHandler).getStatement("some statement");
message.send();
verify(connectionHandler).closeStatement(expectedStatementName);
// CloseResponse
DataInputStream outputResult = inputStreamFromOutputStream(result);
assertEquals('3', outputResult.readByte());
assertEquals(4, outputResult.readInt());
}
use of com.google.cloud.spanner.pgadapter.wireprotocol.ControlMessage.PreparedType in project pgadapter by GoogleCloudPlatform.
the class ProtocolTest method testClosePortalMessage.
@Test
public void testClosePortalMessage() throws Exception {
byte[] messageMetadata = { 'C' };
byte[] statementType = { 'P' };
String statementName = "some portal\0";
byte[] length = intToBytes(4 + statementType.length + statementName.length());
byte[] value = Bytes.concat(messageMetadata, length, statementType, statementName.getBytes());
String expectedStatementName = "some portal";
PreparedType expectedType = PreparedType.Portal;
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(value));
ByteArrayOutputStream result = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(result);
when(connectionHandler.getPortal(anyString())).thenReturn(intermediatePortalStatement);
when(connectionHandler.getConnectionMetadata()).thenReturn(connectionMetadata);
when(connectionMetadata.getInputStream()).thenReturn(inputStream);
when(connectionMetadata.getOutputStream()).thenReturn(outputStream);
WireMessage message = ControlMessage.create(connectionHandler);
assertEquals(CloseMessage.class, message.getClass());
assertEquals(expectedStatementName, ((CloseMessage) message).getName());
assertEquals(expectedType, ((CloseMessage) message).getType());
verify(connectionHandler).getPortal("some portal");
message.send();
verify(intermediatePortalStatement).close();
verify(connectionHandler).closePortal(expectedStatementName);
// CloseResponse
DataInputStream outputResult = inputStreamFromOutputStream(result);
assertEquals('3', outputResult.readByte());
assertEquals(4, outputResult.readInt());
}
Aggregations