Search in sources :

Example 6 with CacheEntry

use of org.apache.accumulo.core.spi.cache.CacheEntry in project accumulo by apache.

the class BlockIndexTest method testSame.

@Test
public void testSame() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    Key prevKey = null;
    int num = 1000;
    for (int i = 0; i < num; i++) {
        Key key = new Key(RFileTest.formatString("", 1), "cf1", "cq1");
        new RelativeKey(prevKey, key).write(out);
        new Value().write(out);
        prevKey = key;
    }
    for (int i = 0; i < num; i++) {
        Key key = new Key(RFileTest.formatString("", 3), "cf1", "cq1");
        new RelativeKey(prevKey, key).write(out);
        new Value().write(out);
        prevKey = key;
    }
    for (int i = 0; i < num; i++) {
        Key key = new Key(RFileTest.formatString("", 5), "cf1", "cq1");
        new RelativeKey(prevKey, key).write(out);
        new Value().write(out);
        prevKey = key;
    }
    out.close();
    final byte[] data = baos.toByteArray();
    CacheEntry ce = new MyCacheEntry(data);
    CachableBlockFile.CachedBlockRead cacheBlock = new CachableBlockFile.CachedBlockRead(ce, data);
    BlockIndex blockIndex = null;
    for (int i = 0; i < 257; i++) blockIndex = BlockIndex.getIndex(cacheBlock, new IndexEntry(prevKey, num, 0, 0, 0));
    assertSame(null, blockIndex.seekBlock(new Key(RFileTest.formatString("", 0), "cf1", "cq1"), cacheBlock));
    assertSame(null, blockIndex.seekBlock(new Key(RFileTest.formatString("", 1), "cf1", "cq1"), cacheBlock));
    for (int i = 2; i < 6; i++) {
        Key seekKey = new Key(RFileTest.formatString("", i), "cf1", "cq1");
        BlockIndexEntry bie = blockIndex.seekBlock(seekKey, cacheBlock);
        assertTrue(bie.getPrevKey().compareTo(seekKey) < 0);
        RelativeKey rk = new RelativeKey();
        rk.setPrevKey(bie.getPrevKey());
        rk.readFields(cacheBlock);
        assertTrue(rk.getKey().compareTo(seekKey) <= 0);
    }
    cacheBlock.close();
}
Also used : DataOutputStream(java.io.DataOutputStream) BlockIndexEntry(org.apache.accumulo.core.file.rfile.BlockIndex.BlockIndexEntry) BlockIndexEntry(org.apache.accumulo.core.file.rfile.BlockIndex.BlockIndexEntry) IndexEntry(org.apache.accumulo.core.file.rfile.MultiLevelIndex.IndexEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheEntry(org.apache.accumulo.core.spi.cache.CacheEntry) Value(org.apache.accumulo.core.data.Value) CachableBlockFile(org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Aggregations

CacheEntry (org.apache.accumulo.core.spi.cache.CacheEntry)6 Test (org.junit.jupiter.api.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 Key (org.apache.accumulo.core.data.Key)2 Value (org.apache.accumulo.core.data.Value)2 CachableBlockFile (org.apache.accumulo.core.file.blockfile.impl.CachableBlockFile)2 BlockIndexEntry (org.apache.accumulo.core.file.rfile.BlockIndex.BlockIndexEntry)2 IndexEntry (org.apache.accumulo.core.file.rfile.MultiLevelIndex.IndexEntry)2 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)1 DefaultConfiguration (org.apache.accumulo.core.conf.DefaultConfiguration)1 BlockCacheConfiguration (org.apache.accumulo.core.file.blockfile.cache.impl.BlockCacheConfiguration)1 CachedBlock (org.apache.accumulo.core.file.blockfile.cache.lru.CachedBlock)1 LruBlockCache (org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCache)1 LruBlockCacheConfiguration (org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheConfiguration)1 LruBlockCacheManager (org.apache.accumulo.core.file.blockfile.cache.lru.LruBlockCacheManager)1