@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);
	}
	Map<String, List<Event>> expectedPattern1 = new HashMap<>();
	expectedPattern1.put("a1", new ArrayList<Event>());
	expectedPattern1.get("a1").add(events[2]);
	expectedPattern1.put("a[]", new ArrayList<Event>());
	expectedPattern1.get("a[]").add(events[3]);
	expectedPattern1.put("b", new ArrayList<Event>());
	expectedPattern1.get("b").add(events[5]);
	Map<String, List<Event>> expectedPattern2 = new HashMap<>();
	expectedPattern2.put("a1", new ArrayList<Event>());
	expectedPattern2.get("a1").add(events[0]);
	expectedPattern2.put("a[]", new ArrayList<Event>());
	expectedPattern2.get("a[]").add(events[1]);
	expectedPattern2.get("a[]").add(events[2]);
	expectedPattern2.get("a[]").add(events[3]);
	expectedPattern2.get("a[]").add(events[4]);
	expectedPattern2.put("b", new ArrayList<Event>());
	expectedPattern2.get("b").add(events[5]);
	Map<String, List<Event>> expectedPattern3 = new HashMap<>();
	expectedPattern3.put("a1", new ArrayList<Event>());
	expectedPattern3.get("a1").add(events[0]);
	expectedPattern3.put("a[]", new ArrayList<Event>());
	expectedPattern3.get("a[]").add(events[1]);
	expectedPattern3.get("a[]").add(events[2]);
	expectedPattern3.get("a[]").add(events[3]);
	expectedPattern3.get("a[]").add(events[4]);
	expectedPattern3.get("a[]").add(events[5]);
	expectedPattern3.get("a[]").add(events[6]);
	expectedPattern3.put("b", new ArrayList<Event>());
	expectedPattern3.get("b").add(events[7]);
	sharedBuffer.put("a1", events[0], timestamp, null, null, 0, 0, DeweyNumber.fromString("1"));
	sharedBuffer.put("a[]", events[1], timestamp, "a1", events[0], timestamp, 0, DeweyNumber.fromString("1.0"));
	sharedBuffer.put("a1", events[2], timestamp, null, null, 0, 0, DeweyNumber.fromString("2"));
	sharedBuffer.put("a[]", events[2], timestamp, "a[]", events[1], timestamp, 1, DeweyNumber.fromString("1.0"));
	sharedBuffer.put("a[]", events[3], timestamp, "a[]", events[2], timestamp, 2, DeweyNumber.fromString("1.0"));
	sharedBuffer.put("a[]", events[3], timestamp, "a1", events[2], timestamp, 0, DeweyNumber.fromString("2.0"));
	sharedBuffer.put("a[]", events[4], timestamp, "a[]", events[3], timestamp, 3, DeweyNumber.fromString("1.0"));
	sharedBuffer.put("b", events[5], timestamp, "a[]", events[4], timestamp, 4, DeweyNumber.fromString("1.0.0"));
	sharedBuffer.put("a[]", events[5], timestamp, "a[]", events[4], timestamp, 4, DeweyNumber.fromString("1.1"));
	sharedBuffer.put("b", events[5], timestamp, "a[]", events[3], timestamp, 1, DeweyNumber.fromString("2.0.0"));
	sharedBuffer.put("a[]", events[6], timestamp, "a[]", events[5], timestamp, 5, DeweyNumber.fromString("1.1"));
	sharedBuffer.put("b", events[7], timestamp, "a[]", events[6], timestamp, 6, DeweyNumber.fromString("1.1.0"));
	Collection<Map<String, List<Event>>> patterns3 = sharedBuffer.extractPatterns("b", events[7], timestamp, 7, DeweyNumber.fromString("1.1.0"));
	sharedBuffer.release("b", events[7], timestamp, 7);
	Collection<Map<String, List<Event>>> patterns4 = sharedBuffer.extractPatterns("b", events[7], timestamp, 7, DeweyNumber.fromString("1.1.0"));
	Collection<Map<String, List<Event>>> patterns1 = sharedBuffer.extractPatterns("b", events[5], timestamp, 2, DeweyNumber.fromString("2.0.0"));
	Collection<Map<String, List<Event>>> patterns2 = sharedBuffer.extractPatterns("b", events[5], timestamp, 5, DeweyNumber.fromString("1.0.0"));
	sharedBuffer.release("b", events[5], timestamp, 2);
	sharedBuffer.release("b", events[5], timestamp, 5);
	assertEquals(1L, patterns3.size());
	assertEquals(0L, patterns4.size());
	assertEquals(1L, patterns1.size());
	assertEquals(1L, patterns2.size());
	assertTrue(sharedBuffer.isEmpty());
	assertTrue(patterns4.isEmpty());
	assertEquals(Collections.singletonList(expectedPattern1), patterns1);
	assertEquals(Collections.singletonList(expectedPattern2), patterns2);
	assertEquals(Collections.singletonList(expectedPattern3), patterns3);
}