public void testDefensiveCopy() { byte[] input = "B".getBytes(); persistence.mutate("A", Functions.constant(input)); input[0]++; if (supportsDefensiveCopy) { assertTrue(Arrays.equals(persistence.get("A"), "B".getBytes())); } else { assertTrue(Arrays.equals(persistence.get("A"), input)); } }
public void testFunctionInput() { persistence.mutate("A", Functions.constant("B".getBytes())); persistence.mutate( "A", new Function<byte[], byte[]>() { @Override public byte[] apply(byte[] fromPersistence) { assertTrue(Arrays.equals(fromPersistence, "B".getBytes())); return "C".getBytes(); } }); assertTrue(Arrays.equals(persistence.get("A"), "C".getBytes())); }
@SuppressWarnings("unchecked") public <T> T main(String[] args) throws Exception { InputStream input = new FileInputStream(new File("myfile")); // HTMObjectInput reader = Persistence.get().serializer().getObjectInput(input); try (HTMObjectInput reader = Persistence.get().serializer().getObjectInput(input)) { Class<?> aClass = null; // ... // Persistable subclass T t = (T) reader.readObject( aClass); // Where T is the Persistable subclass type (HTM.java object). return t; } catch (Exception e) { throw e; } }
public void testDelete() { persistence.mutate("A", Functions.constant("A".getBytes())); assertNull(persistence.mutate("A", Functions.constant((byte[]) null))); assertNull(persistence.get("A")); }
public void testGetUnknownKey() { assertNull(persistence.get("A")); }
public void testOverwrite() { persistence.mutate("A", Functions.constant("A".getBytes())); assertTrue( Arrays.equals("B".getBytes(), persistence.mutate("A", Functions.constant("B".getBytes())))); assertTrue(Arrays.equals(persistence.get("A"), "B".getBytes())); }
public void testBasicSetAndGet() { persistence.mutate("A", Functions.constant("A".getBytes())); assertTrue(Arrays.equals(persistence.get("A"), "A".getBytes())); }