SharedBuffer implements Serializable { public SharedBuffer(final TypeSerializer<V> valueSerializer) { this.valueSerializer = valueSerializer; pages = new HashMap<>(); } SharedBuffer(final TypeSerializer<V> valueSerializer); void put(
			final K key,
			final V value,
			final long timestamp,
			final K previousKey,
			final V previousValue,
			final long previousTimestamp,
			final DeweyNumber version); boolean contains(
		final K key,
		final V value,
		final long timestamp); boolean isEmpty(); void prune(long pruningTimestamp); Collection<LinkedHashMultimap<K, V>> extractPatterns(
		final K key,
		final V value,
		final long timestamp,
		final DeweyNumber version); void lock(final K key, final V value, final long timestamp); void release(final K key, final V value, final long timestamp); void remove(final K key, final V value, final long timestamp); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void testSharedBuffer() { SharedBuffer<String, Event> sharedBuffer = new SharedBuffer<>(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); } LinkedHashMultimap<String, Event> expectedPattern1 = LinkedHashMultimap.create(); expectedPattern1.put("a1", events[2]); expectedPattern1.put("a[]", events[3]); expectedPattern1.put("b", events[5]); LinkedHashMultimap<String, Event> expectedPattern2 = LinkedHashMultimap.create(); expectedPattern2.put("a1", events[0]); expectedPattern2.put("a[]", events[1]); expectedPattern2.put("a[]", events[2]); expectedPattern2.put("a[]", events[3]); expectedPattern2.put("a[]", events[4]); expectedPattern2.put("b", events[5]); LinkedHashMultimap<String, Event> expectedPattern3 = LinkedHashMultimap.create(); expectedPattern3.put("a1", events[0]); expectedPattern3.put("a[]", events[1]); expectedPattern3.put("a[]", events[2]); expectedPattern3.put("a[]", events[3]); expectedPattern3.put("a[]", events[4]); expectedPattern3.put("a[]", events[5]); expectedPattern3.put("a[]", events[6]); expectedPattern3.put("b", events[7]); sharedBuffer.put("a1", events[0], timestamp, null, null, 0, DeweyNumber.fromString("1")); sharedBuffer.put("a[]", events[1], timestamp, "a1", events[0], timestamp, DeweyNumber.fromString("1.0")); sharedBuffer.put("a1", events[2], timestamp, null, null, 0, DeweyNumber.fromString("2")); sharedBuffer.put("a[]", events[2], timestamp, "a[]", events[1], timestamp, DeweyNumber.fromString("1.0")); sharedBuffer.put("a[]", events[3], timestamp, "a[]", events[2], timestamp, DeweyNumber.fromString("1.0")); sharedBuffer.put("a[]", events[3], timestamp, "a1", events[2], timestamp, DeweyNumber.fromString("2.0")); sharedBuffer.put("a[]", events[4], timestamp, "a[]", events[3], timestamp, DeweyNumber.fromString("1.0")); sharedBuffer.put("a[]", events[5], timestamp, "a[]", events[4], timestamp, DeweyNumber.fromString("1.1")); sharedBuffer.put("b", events[5], timestamp, "a[]", events[3], timestamp, DeweyNumber.fromString("2.0.0")); sharedBuffer.put("b", events[5], timestamp, "a[]", events[4], timestamp, DeweyNumber.fromString("1.0.0")); sharedBuffer.put("a[]", events[6], timestamp, "a[]", events[5], timestamp, DeweyNumber.fromString("1.1")); sharedBuffer.put("b", events[7], timestamp, "a[]", events[6], timestamp, DeweyNumber.fromString("1.1.0")); Collection<LinkedHashMultimap<String, Event>> patterns3 = sharedBuffer.extractPatterns("b", events[7], timestamp, DeweyNumber.fromString("1.1.0")); sharedBuffer.remove("b", events[7], timestamp); Collection<LinkedHashMultimap<String, Event>> patterns4 = sharedBuffer.extractPatterns("b", events[7], timestamp, DeweyNumber.fromString("1.1.0")); Collection<LinkedHashMultimap<String, Event>> patterns1 = sharedBuffer.extractPatterns("b", events[5], timestamp, DeweyNumber.fromString("2.0.0")); Collection<LinkedHashMultimap<String, Event>> patterns2 = sharedBuffer.extractPatterns("b", events[5], timestamp, DeweyNumber.fromString("1.0.0")); sharedBuffer.remove("b", events[5], timestamp); assertTrue(sharedBuffer.isEmpty()); assertTrue(patterns4.isEmpty()); assertEquals(Collections.singletonList(expectedPattern1), patterns1); assertEquals(Collections.singletonList(expectedPattern2), patterns2); assertEquals(Collections.singletonList(expectedPattern3), patterns3); }