@Test public void testSerializeRequestWithoutTxn() throws IOException { TxnHeader header = mock(TxnHeader.class); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); OutputArchive oa = (OutputArchive) args[0]; oa.writeString("header", "test"); return null; } }).when(header).serialize(any(OutputArchive.class), anyString()); Request request = new Request(1, 2, 3, header, null, 4); byte[] data = SerializeUtils.serializeRequest(request); assertNotNull(data); verify(header).serialize(any(OutputArchive.class), eq("hdr")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); boa.writeString("header", "test"); baos.close(); assertArrayEquals(baos.toByteArray(), data); }
public static byte[] serializeRequest(Request request) { if (request == null || request.getHdr() == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); try { request.getHdr().serialize(boa, "hdr"); if (request.getTxn() != null) { request.getTxn().serialize(boa, "txn"); } } catch (IOException e) { LOG.error("This really should be impossible", e); } finally { IOUtils.cleanup(LOG, baos); } return baos.toByteArray(); }
SerializeUtils { public static byte[] serializeRequest(Request request) { if (request == null || request.getHdr() == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); try { request.getHdr().serialize(boa, "hdr"); if (request.getTxn() != null) { request.getTxn().serialize(boa, "txn"); } } catch (IOException e) { LOG.error("This really should be impossible", e); } finally { IOUtils.cleanup(LOG, baos); } return baos.toByteArray(); } }
SerializeUtils { public static byte[] serializeRequest(Request request) { if (request == null || request.getHdr() == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); try { request.getHdr().serialize(boa, "hdr"); if (request.getTxn() != null) { request.getTxn().serialize(boa, "txn"); } } catch (IOException e) { LOG.error("This really should be impossible", e); } finally { IOUtils.cleanup(LOG, baos); } return baos.toByteArray(); }  }
SerializeUtils { public static byte[] serializeRequest(Request request) { if (request == null || request.getHdr() == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); try { request.getHdr().serialize(boa, "hdr"); if (request.getTxn() != null) { request.getTxn().serialize(boa, "txn"); } } catch (IOException e) { LOG.error("This really should be impossible", e); } finally { IOUtils.cleanup(LOG, baos); } return baos.toByteArray(); }  static Record deserializeTxn(byte txnBytes[], TxnHeader hdr); static void deserializeSnapshot(DataTree dt,InputArchive ia,
            Map<Long, Integer> sessions); static void serializeSnapshot(DataTree dt,OutputArchive oa,
            Map<Long, Integer> sessions); static byte[] serializeRequest(Request request); }
SerializeUtils { public static byte[] serializeRequest(Request request) { if (request == null || request.getHdr() == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); try { request.getHdr().serialize(boa, "hdr"); if (request.getTxn() != null) { request.getTxn().serialize(boa, "txn"); } } catch (IOException e) { LOG.error("This really should be impossible", e); } finally { IOUtils.cleanup(LOG, baos); } return baos.toByteArray(); }  static Record deserializeTxn(byte txnBytes[], TxnHeader hdr); static void deserializeSnapshot(DataTree dt,InputArchive ia,
            Map<Long, Integer> sessions); static void serializeSnapshot(DataTree dt,OutputArchive oa,
            Map<Long, Integer> sessions); static byte[] serializeRequest(Request request);  }