OnDiskMergeImporterTest.java revision 641e89ef0e15c9edde69f3b8cf82c7dd5f68687a
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2015 ForgeRock AS.
*/
import org.opends.server.backends.pluggable.OnDiskMergeImporter.ExternalSortChunk.InMemorySortedChunk;
public class OnDiskMergeImporterTest extends DirectoryServerTestCase
{
@Test
public void testCollectCursor()
{
{ "key1", "value1key1" },
{ "key1", "value2key1" },
{ "key2", "value1key2" },
{ "key3", "value1key3" },
{ "key3", "value2key3" } }));
final MeteredCursor<ByteString, ByteString> result = new CollectorCursor<>(source, StringConcatCollector.INSTANCE);
{ "key1", "value1key1-value2key1" },
{ "key2", "value1key2" },
{ "key3", "value1key3-value2key3" } }));
}
@Test
public void testCompositeCursor()
{
{ "A", "value1" },
{ "C", "value3" },
{ "D", "value4" },
{ "F", "value6" },
{ "I", "value9" } })));
{ "A", "value1" }, { "E", "value5" }, { "G", "value7" }, { "H", "value8" } })));
{ "A", "value1" },
{ "A", "value1" },
{ "B", "value2" },
{ "C", "value3" },
{ "D", "value4" },
{ "E", "value5" },
{ "F", "value6" },
{ "G", "value7" },
{ "H", "value8" },
{ "I", "value9" } }));
}
@Test
public void testAddLongCollector()
{
final SequentialCursor<String, ByteString> result = new CollectorCursor<>(source, new AddLongCollector(id2count));
}
@Test
public void testEntryIDSetCollector()
{
}
@Test
public void testUniqueValueCollectorAcceptUniqueValues()
{
cursorOf(content(new String[][] { { "key1", "value1" }, { "key2", "value2" }, { "key3", "value3" }, }));
{ "key1", "value1" },
{ "key2", "value2" },
{ "key3", "value3" }, }));
}
public void testUniqueValueCollectorDoesNotAcceptMultipleValues()
{
{ "key1", "value1" },
{ "key2", "value2" },
{ "key2", "value22" },
{ "key3", "value3" } }));
}
@Test
public void testInMemorySortedChunkSortUnsignedOnFlip() throws Exception
{
{ "key1", "value1" },
{ "key2", "value2" },
{ "key3", "value3" },
{ "key1", "value1" },
{ "key2", "value2" },
{ "key3", "value3" },
}
}
@Test
@SuppressWarnings("resource")
public void testFileRegionChunk() throws Exception
{
final int NB_REGION = 10;
final int NB_RECORDS = 15;
final FileChannel channel =
// Generate content
{
{
}
}
// Copy content into file regions
long offset = 0;
{
}
// Verify file regions contents
int regionNumber = 0;
{
regionNumber++;
}
}
@Test
public void testExternalSortChunk() throws Exception
{
final int NB_REGION = 10;
// 4: record offset, 1: key length, 1: value length, 4: value
final ExternalSortChunk chunk =
new ExternalSortChunk(tempDir, "test", bufferPool, StringConcatCollector.INSTANCE, new ForkJoinPool());
for (int i = 0; i < NB_REGION; i++)
{
}
{
assertThat(toPairs(cursor)).containsExactly(Pair.of(KEY, StringConcatCollector.INSTANCE.merge(expected)));
}
}
}
{
{
}
return content;
}
{
{
}
}
{
{
}
return collection;
}
private final static <K, V> MeteredCursor<K, V> cursorOf(@SuppressWarnings("unchecked") Pair<K, V>... pairs)
{
}
{
}
{
private StringConcatCollector()
{
}
{
return new LinkedList<>();
}
{
return resultContainer;
}
{
for (ByteString s : resultContainer)
{
}
return builder.toByteString();
}
}
private static final class IteratorCursorAdapter<K, V> implements MeteredCursor<K, V>
{
{
}
public boolean next()
{
{
return true;
}
return false;
}
public boolean isDefined()
{
}
public K getKey() throws NoSuchElementException
{
}
public V getValue() throws NoSuchElementException
{
}
public void close()
{
}
public long getNbBytesRead()
{
return 0;
}
public long getNbBytesTotal()
{
return 0;
}
public String getMetricName()
{
return "iterator-adapter";
}
}
private static final class DummyIndex extends DefaultIndex
{
private static final EntryContainer entryContainer;
static
{
Mockito.when(entryContainer.getHighestEntryID(Mockito.any(WriteableTransaction.class))).thenReturn(new EntryID(
1));
Mockito.when(state.getIndexFlags(Mockito.any(ReadableTransaction.class), Mockito.any(TreeName.class))).thenReturn(
};
{
}
}
private static final class ArrayListChunk implements Chunk
{
private long size;
{
size +=
PackedLong.getEncodedSize(key.length()) + key.length() + PackedLong.getEncodedSize(value.length()) + value
.length();
return true;
}
{
}
public long size()
{
return size;
}
public void delete()
{
}
}
}