@Test public void testChunk() { RpcDataPackage dataPackage = getDataPackage(); String serviceName = "hello"; String methodName = "testMethod"; dataPackage.serviceName(serviceName); dataPackage.methodName(methodName); byte[] attachment = new byte[] {1, 4}; dataPackage.attachment(attachment); List<RpcDataPackage> chunkList = dataPackage.chunk(0); Assert.assertEquals(1, chunkList.size()); chunkList = dataPackage.chunk(1); Assert.assertEquals(4, chunkList.size()); int pos = 0; Long streamId = null; RpcDataPackage mergedPackage = new RpcDataPackage(); for (RpcDataPackage data : chunkList) { Assert.assertEquals("HULU", data.getHead().getMagicCodeAsString()); Assert.assertEquals(serviceName, data.getRpcMeta().getRequest().getServiceName()); Assert.assertEquals(methodName, data.getRpcMeta().getRequest().getMethodName()); if (pos == 0) { Assert.assertArrayEquals(attachment, data.getAttachment()); } else { Assert.assertNull(data.getAttachment()); } if (streamId != null) { Assert.assertEquals(streamId, data.getRpcMeta().getChunkInfo().getStreamId()); } streamId = data.getRpcMeta().getChunkInfo().getStreamId(); if (pos == 3) { Assert.assertEquals(-1, data.getRpcMeta().getChunkInfo().getChunkId()); } else { Assert.assertEquals(pos, data.getRpcMeta().getChunkInfo().getChunkId()); } pos++; mergedPackage.mergeData(data.getData()); } Assert.assertArrayEquals(dataPackage.getData(), mergedPackage.getData()); }
public List<RpcDataPackage> chunk(long chunkSize) { if (chunkSize < 1 || data == null || chunkSize > data.length) { return Arrays.asList(this); } long streamId = UUID.randomUUID().toString().hashCode(); int chunkId = 0; int startPos = 0; int cSize = Long.valueOf(chunkSize).intValue(); List<RpcDataPackage> ret = new ArrayList<RpcDataPackage>(); while (startPos < data.length) { byte[] subarray = ArrayUtils.subarray(data, startPos, startPos + cSize); RpcDataPackage clone = copy(); clone.data(subarray); if (startPos > 0) { clone.attachment(null); } startPos += cSize; if (startPos >= data.length) { chunkId = -1; } clone.chunkInfo(streamId, chunkId); ret.add(clone); chunkId++; } return ret; }
RpcDataPackage implements Readable, Writerable { public List<RpcDataPackage> chunk(long chunkSize) { if (chunkSize < 1 || data == null || chunkSize > data.length) { return Arrays.asList(this); } long streamId = UUID.randomUUID().toString().hashCode(); int chunkId = 0; int startPos = 0; int cSize = Long.valueOf(chunkSize).intValue(); List<RpcDataPackage> ret = new ArrayList<RpcDataPackage>(); while (startPos < data.length) { byte[] subarray = ArrayUtils.subarray(data, startPos, startPos + cSize); RpcDataPackage clone = copy(); clone.data(subarray); if (startPos > 0) { clone.attachment(null); } startPos += cSize; if (startPos >= data.length) { chunkId = -1; } clone.chunkInfo(streamId, chunkId); ret.add(clone); chunkId++; } return ret; } }
RpcDataPackage implements Readable, Writerable { public List<RpcDataPackage> chunk(long chunkSize) { if (chunkSize < 1 || data == null || chunkSize > data.length) { return Arrays.asList(this); } long streamId = UUID.randomUUID().toString().hashCode(); int chunkId = 0; int startPos = 0; int cSize = Long.valueOf(chunkSize).intValue(); List<RpcDataPackage> ret = new ArrayList<RpcDataPackage>(); while (startPos < data.length) { byte[] subarray = ArrayUtils.subarray(data, startPos, startPos + cSize); RpcDataPackage clone = copy(); clone.data(subarray); if (startPos > 0) { clone.attachment(null); } startPos += cSize; if (startPos >= data.length) { chunkId = -1; } clone.chunkInfo(streamId, chunkId); ret.add(clone); chunkId++; } return ret; }  }
RpcDataPackage implements Readable, Writerable { public List<RpcDataPackage> chunk(long chunkSize) { if (chunkSize < 1 || data == null || chunkSize > data.length) { return Arrays.asList(this); } long streamId = UUID.randomUUID().toString().hashCode(); int chunkId = 0; int startPos = 0; int cSize = Long.valueOf(chunkSize).intValue(); List<RpcDataPackage> ret = new ArrayList<RpcDataPackage>(); while (startPos < data.length) { byte[] subarray = ArrayUtils.subarray(data, startPos, startPos + cSize); RpcDataPackage clone = copy(); clone.data(subarray); if (startPos > 0) { clone.attachment(null); } startPos += cSize; if (startPos >= data.length) { chunkId = -1; } clone.chunkInfo(streamId, chunkId); ret.add(clone); chunkId++; } return ret; }  void mergeData(byte[] data); boolean isChunkPackage(); boolean isFinalPackage(); Long getChunkStreamId(); List<RpcDataPackage> chunk(long chunkSize); RpcDataPackage copy(); RpcDataPackage magicCode(String magicCode); RpcDataPackage serviceName(String serviceName); String serviceName(); String methodName(); RpcDataPackage methodName(String methodName); RpcDataPackage data(byte[] data); RpcDataPackage attachment(byte[] attachment); RpcDataPackage authenticationData(byte[] authenticationData); RpcDataPackage correlationId(long correlationId); RpcDataPackage compressType(int compressType); RpcDataPackage logId(long logId); RpcDataPackage errorCode(int errorCode); RpcDataPackage errorText(String errorText); RpcDataPackage extraParams(byte[] params); RpcDataPackage chunkInfo(long streamId, int chunkId); RpcDataPackage trace(Trace trace); Trace trace(); void setMagicCode(String magicCode); RpcHeadMeta getHead(); void setHead(RpcHeadMeta head); RpcMeta getRpcMeta(); byte[] getData(); void setData(byte[] data); long getTimeStamp(); void setTimeStamp(long timeStamp); byte[] getAttachment(); void setAttachment(byte[] attachment); RpcDataPackage getErrorResponseRpcDataPackage(int errorCode, String errorText); RpcDataPackage getErrorResponseRpcDataPackage(RpcResponseMeta responseMeta); byte[] write(); void read(byte[] bytes); static RpcDataPackage buildRpcDataPackage(RpcMethodInfo methodInfo, Object[] args); }
RpcDataPackage implements Readable, Writerable { public List<RpcDataPackage> chunk(long chunkSize) { if (chunkSize < 1 || data == null || chunkSize > data.length) { return Arrays.asList(this); } long streamId = UUID.randomUUID().toString().hashCode(); int chunkId = 0; int startPos = 0; int cSize = Long.valueOf(chunkSize).intValue(); List<RpcDataPackage> ret = new ArrayList<RpcDataPackage>(); while (startPos < data.length) { byte[] subarray = ArrayUtils.subarray(data, startPos, startPos + cSize); RpcDataPackage clone = copy(); clone.data(subarray); if (startPos > 0) { clone.attachment(null); } startPos += cSize; if (startPos >= data.length) { chunkId = -1; } clone.chunkInfo(streamId, chunkId); ret.add(clone); chunkId++; } return ret; }  void mergeData(byte[] data); boolean isChunkPackage(); boolean isFinalPackage(); Long getChunkStreamId(); List<RpcDataPackage> chunk(long chunkSize); RpcDataPackage copy(); RpcDataPackage magicCode(String magicCode); RpcDataPackage serviceName(String serviceName); String serviceName(); String methodName(); RpcDataPackage methodName(String methodName); RpcDataPackage data(byte[] data); RpcDataPackage attachment(byte[] attachment); RpcDataPackage authenticationData(byte[] authenticationData); RpcDataPackage correlationId(long correlationId); RpcDataPackage compressType(int compressType); RpcDataPackage logId(long logId); RpcDataPackage errorCode(int errorCode); RpcDataPackage errorText(String errorText); RpcDataPackage extraParams(byte[] params); RpcDataPackage chunkInfo(long streamId, int chunkId); RpcDataPackage trace(Trace trace); Trace trace(); void setMagicCode(String magicCode); RpcHeadMeta getHead(); void setHead(RpcHeadMeta head); RpcMeta getRpcMeta(); byte[] getData(); void setData(byte[] data); long getTimeStamp(); void setTimeStamp(long timeStamp); byte[] getAttachment(); void setAttachment(byte[] attachment); RpcDataPackage getErrorResponseRpcDataPackage(int errorCode, String errorText); RpcDataPackage getErrorResponseRpcDataPackage(RpcResponseMeta responseMeta); byte[] write(); void read(byte[] bytes); static RpcDataPackage buildRpcDataPackage(RpcMethodInfo methodInfo, Object[] args);  }