Search in sources :

Example 6 with PageId

use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.

the class LocalPageStoreTest method testSingleFileBucket.

@Test
public void testSingleFileBucket() throws Exception {
    mOptions.setFileBuckets(1);
    LocalPageStore pageStore = new LocalPageStore(mOptions);
    long numFiles = 100;
    for (int i = 0; i < numFiles; i++) {
        PageId id = new PageId(Integer.toString(i), 0);
        pageStore.put(id, "test".getBytes());
    }
    long actualCount = 0;
    for (Path root : mOptions.getRootDirs()) {
        actualCount += Files.list(Paths.get(root.toString(), Long.toString(mOptions.getPageSize()))).count();
    }
    assertEquals(mRootDirCount, actualCount);
}
Also used : PageId(alluxio.client.file.cache.PageId) Path(java.nio.file.Path) Test(org.junit.Test)

Example 7 with PageId

use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.

the class PageStoreTest method getPages.

@Test
public void getPages() throws Exception {
    int len = 32;
    int count = 16;
    byte[] data = BufferUtils.getIncreasingByteArray(len);
    Set<PageInfo> pages = new HashSet<>(count);
    for (int i = 0; i < count; i++) {
        PageId id = new PageId("0", i);
        mPageStore.put(id, data);
        pages.add(new PageInfo(id, data.length));
    }
    Set<PageInfo> restored = mPageStore.getPages().collect(Collectors.toSet());
    assertEquals(pages, restored);
}
Also used : PageId(alluxio.client.file.cache.PageId) PageInfo(alluxio.client.file.cache.PageInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with PageId

use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.

the class PageStoreTest method helloWorldTest.

@Test
public void helloWorldTest() throws Exception {
    String msg = "Hello, World!";
    byte[] msgBytes = msg.getBytes();
    PageId id = new PageId("0", 0);
    mPageStore.put(id, msgBytes);
    byte[] buf = new byte[1024];
    assertEquals(msgBytes.length, mPageStore.get(id, buf));
    assertArrayEquals(msgBytes, Arrays.copyOfRange(buf, 0, msgBytes.length));
    mPageStore.delete(id);
    try {
        mPageStore.get(id, buf);
        fail();
    } catch (PageNotFoundException e) {
    // Test completed successfully;
    }
}
Also used : PageId(alluxio.client.file.cache.PageId) PageNotFoundException(alluxio.exception.PageNotFoundException) Test(org.junit.Test)

Example 9 with PageId

use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.

the class PageStoreTest method getPagesUUID.

@Test
public void getPagesUUID() throws Exception {
    int len = 32;
    int count = 16;
    byte[] data = BufferUtils.getIncreasingByteArray(len);
    Set<PageInfo> pages = new HashSet<>(count);
    for (int i = 0; i < count; i++) {
        PageId id = new PageId(UUID.randomUUID().toString(), i);
        mPageStore.put(id, data);
        pages.add(new PageInfo(id, data.length));
    }
    Set<PageInfo> restored = mPageStore.getPages().collect(Collectors.toSet());
    assertEquals(pages, restored);
}
Also used : PageId(alluxio.client.file.cache.PageId) PageInfo(alluxio.client.file.cache.PageInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with PageId

use of alluxio.client.file.cache.PageId in project alluxio by Alluxio.

the class PageStoreTest method getOffsetOverflow.

@Test
public void getOffsetOverflow() throws Exception {
    int len = 32;
    int offset = 36;
    PageId id = new PageId("0", 0);
    mPageStore.put(id, BufferUtils.getIncreasingByteArray(len));
    byte[] buf = new byte[1024];
    assertThrows(IllegalArgumentException.class, () -> mPageStore.get(id, offset, len, buf, 0));
}
Also used : PageId(alluxio.client.file.cache.PageId) Test(org.junit.Test)

Aggregations

PageId (alluxio.client.file.cache.PageId)22 Test (org.junit.Test)11 Nullable (javax.annotation.Nullable)5 PageNotFoundException (alluxio.exception.PageNotFoundException)4 PageInfo (alluxio.client.file.cache.PageInfo)3 Path (java.nio.file.Path)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ResourceExhaustedException (alluxio.exception.status.ResourceExhaustedException)1 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Matcher (java.util.regex.Matcher)1