private byte[] marshall(Object key) { try { return (key instanceof WrappedByteArray) ? ((WrappedByteArray) key).getBytes() : this.ctx.getMarshaller().objectToByteBuffer(key); } catch (IOException | InterruptedException e) { throw new PersistenceException(e); } }
@Override public byte[] objectToByteBuffer(Object obj, int estimatedSize) throws IOException, InterruptedException { return marshaller.objectToByteBuffer(obj, estimatedSize); }
@Override public byte[] objectToByteBuffer(Object obj) throws IOException, InterruptedException { return marshaller.objectToByteBuffer(obj); }
protected void marshallAndAssertArrayEquality(Object[] writeObj) throws Exception { byte[] bytes = marshaller.objectToByteBuffer(writeObj); log.debugf("Payload size for %s[]=%s : %s", writeObj.getClass().getComponentType().getName(), Arrays.toString(writeObj), bytes.length); Object[] readObj = (Object[]) marshaller.objectFromByteBuffer(bytes); assertArrayEquals("Writen[" + Arrays.toString(writeObj) + "] and read[" + Arrays.toString(readObj) + "] objects should be the same", writeObj, readObj); }
public void testMIMECacheEntryMarshalling() throws Exception { MIMECacheEntry entry = new MIMECacheEntry("rm", new byte[] {1, 2, 3}); byte[] bytes = marshaller.objectToByteBuffer(entry); MIMECacheEntry rEntry = (MIMECacheEntry) marshaller.objectFromByteBuffer(bytes); assert Arrays.equals(rEntry.data, entry.data); assert rEntry.contentType.equals(entry.contentType); }
protected void marshallAndAssertEquality(Object writeObj) throws Exception { byte[] bytes = marshaller.objectToByteBuffer(writeObj); log.debugf("Payload size for object=%s : %s", writeObj, bytes.length); Object readObj = marshaller.objectFromByteBuffer(bytes); assert readObj.equals(writeObj) : "Writen[" + writeObj + "] and read[" + readObj + "] objects should be the same"; }
public void testNonSerializable() throws Exception { try { marshaller.objectToByteBuffer(new Object()); } catch (NotSerializableException e) { log.info("Log exception for output format verification", e); TraceInformation inf = (TraceInformation) e.getCause(); if (inf != null) { assert inf.toString().contains("in object java.lang.Object@"); } } }
public void testErrorUnmarshallInputStreamAvailable() throws Exception { byte[] bytes = marshaller.objectToByteBuffer("23"); Object o = marshaller.objectFromInputStream(new ByteArrayInputStream(bytes){ @Override public int available() { return 0; } }); assertEquals("23", o); }
public void testMarshallingBigByteArrayValue() throws IOException, InterruptedException, ClassNotFoundException { byte[] cacheValue = getBigByteArray(); byte[] bytes = marshaller.objectToByteBuffer(cacheValue); byte[] readValue = (byte[]) marshaller.objectFromByteBuffer(bytes); AssertJUnit.assertTrue(Arrays.equals(readValue, cacheValue)); } }
public void testErrorUnmarshalling() throws Exception { Pojo pojo = new PojoWhichFailsOnUnmarshalling(); byte[] bytes = marshaller.objectToByteBuffer(pojo); try { marshaller.objectFromByteBuffer(bytes); } catch (IOException e) { log.info("Log exception for output format verification", e); TraceInformation inf = (TraceInformation) e.getCause(); if (inf != null) assert inf.toString().contains("in object of type org.infinispan.marshall.VersionAwareMarshallerTest$PojoWhichFailsOnUnmarshalling"); } }
private byte[] marshall(String contentType, MarshalledEntry entry) throws IOException, InterruptedException { if (configuration.rawValues()) { return (byte[]) entry.getValue(); } else { if (isTextContentType(contentType)) { return (byte[]) entry.getValue(); } return ctx.getMarshaller().objectToByteBuffer(entry.getValue()); } }
private byte[] serialize(MarshalledEntry o) { try { return marshaller.objectToByteBuffer(new KeyValuePair(o.getValue(), o.getMetadata())); } catch (IOException e) { throw new CacheException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new CacheException(e); } }
public void testExceptionResponse() throws Exception { ExceptionResponse er = new ExceptionResponse(new TimeoutException()); byte[] bytes = marshaller.objectToByteBuffer(er); ExceptionResponse rer = (ExceptionResponse) marshaller.objectFromByteBuffer(bytes); assert rer.getException().getClass().equals(er.getException().getClass()) : "Writen[" + er.getException().getClass() + "] and read[" + rer.getException().getClass() + "] objects should be the same"; }
public void testEqualsAndHashCode() throws Exception { StreamingMarshaller marshaller = extractGlobalMarshaller(cache(0).getCacheManager()); Pojo pojo = new Pojo(); WrappedBytes wb = new WrappedByteArray(marshaller.objectToByteBuffer(pojo)); WrappedBytes wb2 = new WrappedByteArray(marshaller.objectToByteBuffer(pojo)); assertTrue(wb2.hashCode() == wb.hashCode()); assertEquals(wb, wb2); }
public void testMarshallingBigByteArrayKey() throws Exception { byte[] cacheKey = getBigByteArray(); byte[] bytes = marshaller.objectToByteBuffer(cacheKey); byte[] readKey = (byte[]) marshaller.objectFromByteBuffer(bytes); assertEquals(readKey, cacheKey); }
protected void marshallAndAssertEquality(ReplicableCommand writeObj) throws Exception { byte[] bytes = marshaller.objectToByteBuffer(writeObj); log.debugf("Payload size for object=%s : %s", writeObj, bytes.length); ReplicableCommand readObj = (ReplicableCommand) marshaller.objectFromByteBuffer(bytes); assert readObj.getCommandId() == writeObj.getCommandId() : "Writen[" + writeObj.getCommandId() + "] and read[" + readObj.getCommandId() + "] objects should be the same"; assert readObj.equals(writeObj) : "Writen[" + writeObj + "] and read[" + readObj + "] objects should be the same"; }
public void testMarshallingSerializableSubclass() throws Exception { Child1 child1Obj = new Child1(1234, "1234"); byte[] bytes = marshaller.objectToByteBuffer(child1Obj); Child1 readChild1 = (Child1) marshaller.objectFromByteBuffer(bytes); assertEquals(1234, readChild1.someInt); assertEquals("1234", readChild1.getId()); }
protected void marshallAndAssertByteArrayEquality(byte[] writeObj) throws Exception { byte[] bytes = marshaller.objectToByteBuffer(writeObj); log.debugf("Payload size for byte[]=%s : %s", Util.toHexString(writeObj), bytes.length); byte[] readObj = (byte[]) marshaller.objectFromByteBuffer(bytes); assertArrayEquals("Writen[" + Util.toHexString(writeObj)+ "] and read[" + Util.toHexString(readObj)+ "] objects should be the same", writeObj, readObj); }
public void testExternalAndInternalWithOffset() throws Exception { PojoWithExternalAndInternal obj = new PojoWithExternalAndInternal(new Human().age(23), "value"); byte[] bytes = marshaller.objectToByteBuffer(obj); bytes = prependBytes(new byte[]{1, 2, 3}, bytes); Object readObj = marshaller.objectFromByteBuffer(bytes, 3, bytes.length); assertEquals(obj, readObj); }
public void testMarshallingNestedSerializableSubclass() throws Exception { Child1 child1Obj = new Child1(1234, "1234"); Child2 child2Obj = new Child2(2345, "2345", child1Obj); byte[] bytes = marshaller.objectToByteBuffer(child2Obj); Child2 readChild2 = (Child2) marshaller.objectFromByteBuffer(bytes); assertEquals(2345, readChild2.someInt); assertEquals("2345", readChild2.getId()); assertEquals(1234, readChild2.getChild1Obj().someInt); assertEquals("1234", readChild2.getChild1Obj().getId()); }