Package org.infinispan.marshall.core

Examples of org.infinispan.marshall.core.MarshalledValue$Externalizer


      }
   }

   private Object compact(Object val) {
      if (val instanceof MarshalledValue) {
         MarshalledValue marshalled = (MarshalledValue) val;
         if (marshalled.getRaw().size() < marshalled.getRaw().getRaw().length) {
            byte[] compactedArray = Arrays.copyOfRange(marshalled.getRaw().getRaw(), 0, marshalled.getRaw().size());
            return new MarshalledValue(compactedArray, marshalled.hashCode(), marshalled.getMarshaller());
         }
      }
      return val;
   }
View Full Code Here


   }

   public void testMarshalledValueMarshalling() throws Exception {
      Person p = new Person();
      p.setName("Bob Dylan");
      MarshalledValue mv = new MarshalledValue(p, true, marshaller);
      marshallAndAssertEquality(mv);
   }
View Full Code Here

      marshallAndAssertEquality(mv);
   }

   public void testMarshalledValueGetMarshalling() throws Exception {
      Pojo ext = new Pojo();
      MarshalledValue mv = new MarshalledValue(ext, true, marshaller);
      byte[] bytes = marshaller.objectToByteBuffer(mv);
      MarshalledValue rmv = (MarshalledValue) marshaller.objectFromByteBuffer(bytes);
      assert rmv.equals(mv) : "Writen[" + mv + "] and read[" + rmv + "] objects should be the same";
      assert rmv.get() instanceof Pojo;
   }
View Full Code Here

      DataContainer dc1 = TestingUtil.extractComponent(cache1, DataContainer.class);

      InternalCacheEntry ice = dc1.get("key");
      Object o = ice.getValue();
      assertTrue(o instanceof MarshalledValue);
      MarshalledValue mv = (MarshalledValue) o;
      assertDeserialized(mv);
      assertEquals(value, cache1.get("key"));
      assertDeserialized(mv);
      assertSerializationCounts(1, 0);
      cache1.compact();
View Full Code Here

      DataContainer dc1 = TestingUtil.extractComponent(cache1, DataContainer.class);

      Object o = dc1.keySet().iterator().next();
      assertTrue(o instanceof MarshalledValue);
      MarshalledValue mv = (MarshalledValue) o;
      assertDeserialized(mv);

      assertEquals("value", cache1.get(key));
      assertDeserialized(mv);
      assertSerializationCounts(1, 0);
View Full Code Here

      }
   }

   public void testEqualsAndHashCode() throws Exception {
      Pojo pojo = new Pojo();
      MarshalledValue mv = new MarshalledValue(pojo, true, extractCacheMarshaller(cache(0)));
      assertDeserialized(mv);
      int oldHashCode = mv.hashCode();

      mv.serialize();
      assertSerialized(mv);
      assertTrue(oldHashCode == mv.hashCode());

      MarshalledValue mv2 = new MarshalledValue(pojo, true, extractCacheMarshaller(cache(0)));
      assertSerialized(mv);
      assertDeserialized(mv2);

      assertTrue(mv2.hashCode() == oldHashCode);
      assertEquals(mv, mv2);
   }
View Full Code Here

   public void testEquality() {
      byte[] prevBytes = TestingUtil.generateRandomString(1310)
            .getBytes(Charset.forName("UTF-8"));

      String value = "galder";
      MarshalledValue mv = new MarshalledValue(
            value, true, extractCacheMarshaller(cache(0, "replSync")));
      MarshalledValue mv2 = new MarshalledValue(
            value, false, extractCacheMarshaller(cache(0, "replSync")));

      // Simulate that the marshalled value had a bigger value before
      mv2.instance = prevBytes;
      mv2.serialize();
      // Now back to the original instance and force it to serialize again
      mv2.instance = value;
      mv2.raw = null;
      mv2.serialize();
      mv2.instance = null;

      assertEquals(mv, mv2);
   }
View Full Code Here

      assert null == cs.load("k1");
   }

   public void testLoadAndStoreMarshalledValues() throws CacheLoaderException {
      MarshalledValue key = new MarshalledValue(new Pojo().role("key"), true, getMarshaller());
      MarshalledValue key2 = new MarshalledValue(new Pojo().role("key2"), true, getMarshaller());
      MarshalledValue value = new MarshalledValue(new Pojo().role("value"), true, getMarshaller());

      assert !cs.containsKey(key);
      InternalCacheEntry se = TestInternalCacheEntryFactory.create(key, value);
      cs.store(se);
View Full Code Here

   }

   public void testMarshalledValueMarshalling() throws Exception {
      Person p = new Person();
      p.setName("Bob Dylan");
      MarshalledValue mv = new MarshalledValue(p, marshaller);
      marshallAndAssertEquality(mv);
   }
View Full Code Here

      marshallAndAssertEquality(mv);
   }

   public void testMarshalledValueGetMarshalling() throws Exception {
      Pojo ext = new Pojo();
      MarshalledValue mv = new MarshalledValue(ext, marshaller);
      byte[] bytes = marshaller.objectToByteBuffer(mv);
      MarshalledValue rmv = (MarshalledValue) marshaller.objectFromByteBuffer(bytes);
      assert rmv.equals(mv) : "Writen[" + mv + "] and read[" + rmv + "] objects should be the same";
      assert rmv.get() instanceof Pojo;
   }
View Full Code Here

TOP

Related Classes of org.infinispan.marshall.core.MarshalledValue$Externalizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.