@VisibleForTesting
    public SharedBuffer(KeyedStateStore stateStore, TypeSerializer<V> valueSerializer) {
        this(stateStore, valueSerializer, new SharedBufferCacheConfig());
    }
@Test
    public void testSharedBuffer() throws Exception {
        SharedBuffer<Event> sharedBuffer =
                TestSharedBuffer.createTestBuffer(Event.createTypeSerializer(), cacheConfig);
        int numberEvents = 8;
        Event[] events = new Event[numberEvents];
        EventId[] eventIds = new EventId[numberEvents];
        final long timestamp = 1L;

        for (int i = 0; i < numberEvents; i++) {
            events[i] = new Event(i + 1, "e" + (i + 1), i);
            eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp);
        }

        Map<String, List<Event>> expectedPattern1 = new HashMap<>();
        expectedPattern1.put("a1", new ArrayList<>());
        expectedPattern1.get("a1").add(events[2]);

        expectedPattern1.put("a[]", new ArrayList<>());
        expectedPattern1.get("a[]").add(events[3]);

        expectedPattern1.put("b", new ArrayList<>());
        expectedPattern1.get("b").add(events[5]);

        Map<String, List<Event>> expectedPattern2 = new HashMap<>();
        expectedPattern2.put("a1", new ArrayList<>());
        expectedPattern2.get("a1").add(events[0]);

        expectedPattern2.put("a[]", new ArrayList<>());
        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<>());
        expectedPattern2.get("b").add(events[5]);

        Map<String, List<Event>> expectedPattern3 = new HashMap<>();
        expectedPattern3.put("a1", new ArrayList<>());
        expectedPattern3.get("a1").add(events[0]);

        expectedPattern3.put("a[]", new ArrayList<>());
        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<>());
        expectedPattern3.get("b").add(events[7]);

        try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) {
            NodeId a10 =
                    sharedBufferAccessor.put("a1", eventIds[0], null, DeweyNumber.fromString("1"));
            NodeId aLoop0 =
                    sharedBufferAccessor.put(
                            "a[]", eventIds[1], a10, DeweyNumber.fromString("1.0"));
            NodeId a11 =
                    sharedBufferAccessor.put("a1", eventIds[2], null, DeweyNumber.fromString("2"));
            NodeId aLoop1 =
                    sharedBufferAccessor.put(
                            "a[]", eventIds[2], aLoop0, DeweyNumber.fromString("1.0"));
            NodeId aLoop2 =
                    sharedBufferAccessor.put(
                            "a[]", eventIds[3], aLoop1, DeweyNumber.fromString("1.0"));
            NodeId aSecondLoop0 =
                    sharedBufferAccessor.put(
                            "a[]", eventIds[3], a11, DeweyNumber.fromString("2.0"));
            NodeId aLoop3 =
                    sharedBufferAccessor.put(
                            "a[]", eventIds[4], aLoop2, DeweyNumber.fromString("1.0"));
            DeweyNumber b0Version = DeweyNumber.fromString("1.0.0");
            NodeId b0 = sharedBufferAccessor.put("b", eventIds[5], aLoop3, b0Version);
            NodeId aLoop4 =
                    sharedBufferAccessor.put(
                            "a[]", eventIds[5], aLoop3, DeweyNumber.fromString("1.1"));
            DeweyNumber b1Version = DeweyNumber.fromString("2.0.0");
            NodeId b1 = sharedBufferAccessor.put("b", eventIds[5], aSecondLoop0, b1Version);
            NodeId aLoop5 =
                    sharedBufferAccessor.put(
                            "a[]", eventIds[6], aLoop4, DeweyNumber.fromString("1.1"));
            DeweyNumber b3Version = DeweyNumber.fromString("1.1.0");
            NodeId b3 = sharedBufferAccessor.put("b", eventIds[7], aLoop5, b3Version);
            sharedBufferAccessor.lockNode(b0, b0Version);
            sharedBufferAccessor.lockNode(b1, b1Version);
            sharedBufferAccessor.lockNode(b3, b3Version);

            List<Map<String, List<EventId>>> patterns3 =
                    sharedBufferAccessor.extractPatterns(b3, b3Version);
            assertEquals(1L, patterns3.size());
            assertEquals(expectedPattern3, sharedBufferAccessor.materializeMatch(patterns3.get(0)));
            sharedBufferAccessor.releaseNode(b3, b3Version);

            List<Map<String, List<EventId>>> patterns4 =
                    sharedBufferAccessor.extractPatterns(b3, b3Version);
            assertEquals(0L, patterns4.size());
            assertTrue(patterns4.isEmpty());

            List<Map<String, List<EventId>>> patterns1 =
                    sharedBufferAccessor.extractPatterns(b1, b1Version);
            assertEquals(1L, patterns1.size());
            assertEquals(expectedPattern1, sharedBufferAccessor.materializeMatch(patterns1.get(0)));
            sharedBufferAccessor.releaseNode(b1, b1Version);

            List<Map<String, List<EventId>>> patterns2 =
                    sharedBufferAccessor.extractPatterns(b0, b0Version);
            assertEquals(1L, patterns2.size());
            assertEquals(expectedPattern2, sharedBufferAccessor.materializeMatch(patterns2.get(0)));
            sharedBufferAccessor.releaseNode(b0, b0Version);

            for (EventId eventId : eventIds) {
                sharedBufferAccessor.releaseEvent(eventId);
            }
        }

        assertTrue(sharedBuffer.isEmpty());
    }