Search in sources :

Example 6 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkRebuild.

@Test
public void checkRebuild() {
    int lgK = 9;
    int k = 1 << lgK;
    int u = 4 * k;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    assertTrue(local.isEmpty());
    for (int i = 0; i < u; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    assertFalse(local.isEmpty());
    assertTrue(local.getEstimate() > 0.0);
    assertTrue(shared.getRetainedEntries(false) >= k);
    shared.rebuild();
    assertEquals(shared.getRetainedEntries(false), k);
    assertEquals(shared.getRetainedEntries(true), k);
    local.rebuild();
    assertEquals(shared.getRetainedEntries(false), k);
    assertEquals(shared.getRetainedEntries(true), k);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 7 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkExactModeMemoryArr.

@Test
public void checkExactModeMemoryArr() {
    int lgK = 12;
    int k = 1 << lgK;
    int u = k;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    assertTrue(local.isEmpty());
    for (int i = 0; i < u; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    assertEquals(local.getEstimate(), u, 0.0);
    assertEquals(shared.getRetainedEntries(false), u);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 8 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkEstModeNativeMemory.

@Test
public void checkEstModeNativeMemory() {
    int lgK = 12;
    int k = 1 << lgK;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    assertTrue(local.isEmpty());
    int u = 3 * k;
    for (int i = 0; i < u; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    double est = local.getEstimate();
    assertTrue((est < (u * 1.05)) && (est > (u * 0.95)));
    assertTrue(shared.getRetainedEntries(false) >= k);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 9 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkWrapIllegalFamilyID_direct.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkWrapIllegalFamilyID_direct() {
    int lgK = 9;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    // corrupt the Sketch ID byte
    sl.wmem.putByte(FAMILY_BYTE, (byte) 0);
    // try to wrap the corrupted mem
    DirectQuickSelectSketch.writableWrap(sl.wmem, DEFAULT_UPDATE_SEED);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 10 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkResetAndStartingSubMultiple.

@Test
public void checkResetAndStartingSubMultiple() {
    int lgK = 9;
    int k = 1 << lgK;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    assertTrue(local.isEmpty());
    int u = 4 * k;
    for (int i = 0; i < u; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    assertFalse(local.isEmpty());
    assertTrue(shared.getRetainedEntries(false) >= k);
    assertTrue(local.getThetaLong() < Long.MAX_VALUE);
    shared.reset();
    local.reset();
    assertTrue(local.isEmpty());
    assertEquals(shared.getRetainedEntries(false), 0);
    assertEquals(local.getEstimate(), 0.0, 0.0);
    assertEquals(local.getThetaLong(), Long.MAX_VALUE);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Aggregations

SharedLocal (org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal)26 Test (org.testng.annotations.Test)26 WritableMemory (org.apache.datasketches.memory.WritableMemory)6 Memory (org.apache.datasketches.memory.Memory)3