BufferManager implements Serializers, AutoCloseable { public <T> DistinctBufferMaker<T> createDistinctBuffer( Serializer<T> distinctSerializer ) { return new MakeDistinctBuffer<T>("buffer-" + dbCounter.incrementAndGet(), distinctSerializer); } BufferManager( ExecutionContext context ); protected  BufferManager( ExecutionContext context,
                             Supplier<DB> offheapDbSupplier,
                             Supplier<DB> onheapDbSupplier ); @Override void close(); QueueBufferMaker<T> createQueueBuffer( Serializer<T> serializer ); DistinctBufferMaker<T> createDistinctBuffer( Serializer<T> distinctSerializer ); SortingBufferMaker<K, V> createSortingBuffer( BTreeKeySerializer<K> keySerializer,
                                                                Serializer<V> valueSerializer ); SortingBufferMaker<K, V> createSortingWithDuplicatesBuffer( Serializer<K> keySerializer,
                                                                                                    Comparator<?> keyComparator,
                                                                                                    Serializer<V> valueSerializer ); @Override Serializer<?> serializerFor( Class<?> type ); @Override BTreeKeySerializer<?> bTreeKeySerializerFor( Class<?> type,
                                                        Comparator<?> comparator,
                                                        boolean pack ); @Override Serializer<?> nullSafeSerializerFor( Class<?> type ); Serializer<?> serializerFor( TypeFactory<?> type ); Serializer<?> nullSafeSerializerFor( TypeFactory<?> type ); BTreeKeySerializer<?> bTreeKeySerializerFor( TypeFactory<?> type,
                                                        boolean pack );  }
@Test public void shouldCreateDistinctBufferOnHeap() { try (DistinctBuffer<String> buffer = mgr.createDistinctBuffer(Serializer.STRING).useHeap(true).keepSize(true).make()) { assertTrue(buffer.addIfAbsent("first")); assertTrue(buffer.addIfAbsent("second")); assertTrue(buffer.addIfAbsent("third")); assertTrue(buffer.addIfAbsent("fourth")); assertFalse(buffer.addIfAbsent("first")); assertFalse(buffer.addIfAbsent("second")); assertFalse(buffer.addIfAbsent("fourth")); assertFalse(buffer.addIfAbsent("third")); assertThat(buffer.size(), is(4L)); } }
@Test public void shouldCreateDistinctBufferOffHeap() { try (DistinctBuffer<String> buffer = mgr.createDistinctBuffer(Serializer.STRING).useHeap(false).keepSize(true).make()) { assertTrue(buffer.addIfAbsent("first")); assertTrue(buffer.addIfAbsent("second")); assertTrue(buffer.addIfAbsent("third")); assertTrue(buffer.addIfAbsent("fourth")); assertFalse(buffer.addIfAbsent("first")); assertFalse(buffer.addIfAbsent("second")); assertFalse(buffer.addIfAbsent("fourth")); assertFalse(buffer.addIfAbsent("third")); assertThat(buffer.size(), is(4L)); } }