Search in sources :

Example 1 with CopyDoneMessage

use of com.google.cloud.spanner.pgadapter.wireprotocol.CopyDoneMessage in project pgadapter by GoogleCloudPlatform.

the class ProtocolTest method testCopyDoneMessage.

@Test
public void testCopyDoneMessage() throws Exception {
    byte[] messageMetadata = { 'c' };
    byte[] length = intToBytes(4);
    byte[] value = Bytes.concat(messageMetadata, length);
    DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(value));
    ByteArrayOutputStream result = new ByteArrayOutputStream();
    DataOutputStream outputStream = new DataOutputStream(result);
    CopyStatement copyStatement = mock(CopyStatement.class);
    when(connectionHandler.getActiveStatement()).thenReturn(copyStatement);
    when(connectionHandler.getConnectionMetadata()).thenReturn(connectionMetadata);
    when(connectionHandler.getStatus()).thenReturn(ConnectionStatus.COPY_IN);
    when(connectionMetadata.getInputStream()).thenReturn(inputStream);
    when(connectionMetadata.getOutputStream()).thenReturn(outputStream);
    MutationWriter mb = mock(MutationWriter.class);
    when(copyStatement.getMutationWriter()).thenReturn(mb);
    WireMessage message = ControlMessage.create(connectionHandler);
    assertEquals(CopyDoneMessage.class, message.getClass());
    CopyDoneMessage messageSpy = (CopyDoneMessage) spy(message);
    doReturn(false).when(messageSpy).sendSpannerResult(anyInt(), any(IntermediateStatement.class), any(QueryMode.class), anyLong());
    messageSpy.send();
    verify(messageSpy).sendSpannerResult(0, copyStatement, QueryMode.SIMPLE, 0L);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CopyStatement(com.google.cloud.spanner.pgadapter.statements.CopyStatement) DataOutputStream(java.io.DataOutputStream) QueryMode(com.google.cloud.spanner.pgadapter.ConnectionHandler.QueryMode) MutationWriter(com.google.cloud.spanner.pgadapter.utils.MutationWriter) WireMessage(com.google.cloud.spanner.pgadapter.wireprotocol.WireMessage) IntermediateStatement(com.google.cloud.spanner.pgadapter.statements.IntermediateStatement) CopyDoneMessage(com.google.cloud.spanner.pgadapter.wireprotocol.CopyDoneMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Aggregations

QueryMode (com.google.cloud.spanner.pgadapter.ConnectionHandler.QueryMode)1 CopyStatement (com.google.cloud.spanner.pgadapter.statements.CopyStatement)1 IntermediateStatement (com.google.cloud.spanner.pgadapter.statements.IntermediateStatement)1 MutationWriter (com.google.cloud.spanner.pgadapter.utils.MutationWriter)1 CopyDoneMessage (com.google.cloud.spanner.pgadapter.wireprotocol.CopyDoneMessage)1 WireMessage (com.google.cloud.spanner.pgadapter.wireprotocol.WireMessage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 Test (org.junit.Test)1