ProtobufHandler extends AbstractHandler<byte[]> { @Override public HandlerResponse<byte[]> apply(byte[] requestBytes) { return super.apply(requestBytes); } ProtobufHandler(Service service, ProtobufTranslation translation); @Override HandlerResponse<byte[]> apply(byte[] requestBytes);  }
@Test public void testFetch() throws Exception { final String connectionId = "cnxn1"; final int statementId = 30; final long offset = 10; final int fetchMaxRowCount = 100; final List<Common.TypedValue> values = new ArrayList<>(); values.add(Common.TypedValue.newBuilder().setType(Common.Rep.BOOLEAN).setBoolValue(true) .build()); values.add(Common.TypedValue.newBuilder().setType(Common.Rep.STRING) .setStringValue("my_string").build()); Requests.FetchRequest protoRequest = Requests.FetchRequest.newBuilder() .setConnectionId(connectionId).setStatementId(statementId) .setOffset(offset).setFetchMaxRowCount(fetchMaxRowCount) .build(); byte[] serializedRequest = protoRequest.toByteArray(); FetchRequest request = new FetchRequest().deserialize(protoRequest); List<Object> frameRows = new ArrayList<>(); frameRows.add(new Object[] {true, "my_string"}); Meta.Frame frame = Frame.create(0, true, frameRows); FetchResponse response = new FetchResponse(frame, false, false); when(translation.parseRequest(serializedRequest)).thenReturn(request); when(service.apply(request)).thenReturn(response); when(translation.serializeResponse(response)) .thenReturn(response.serialize().toByteArray()); HandlerResponse<byte[]> handlerResponse = handler.apply(serializedRequest); byte[] serializedResponse = handlerResponse.getResponse(); assertEquals(200, handlerResponse.getStatusCode()); Responses.FetchResponse protoResponse = Responses.FetchResponse.parseFrom(serializedResponse); Common.Frame protoFrame = protoResponse.getFrame(); assertEquals(frame.offset, protoFrame.getOffset()); assertEquals(frame.done, protoFrame.getDone()); List<Common.Row> rows = protoFrame.getRowsList(); assertEquals(1, rows.size()); Common.Row row = rows.get(0); List<Common.ColumnValue> columnValues = row.getValueList(); assertEquals(2, columnValues.size()); Iterator<Common.ColumnValue> iter = columnValues.iterator(); assertTrue(iter.hasNext()); Common.ColumnValue column = iter.next(); assertEquals(1, column.getValueCount()); Common.TypedValue value = column.getValue(0); assertEquals(Common.Rep.BOOLEAN, value.getType()); assertEquals(true, value.getBoolValue()); assertTrue(iter.hasNext()); column = iter.next(); assertEquals(1, column.getValueCount()); value = column.getValue(0); assertEquals(Common.Rep.STRING, value.getType()); assertEquals("my_string", value.getStringValue()); }