Search in sources :

Example 16 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkBackgroundPropagation.

@Test
public void checkBackgroundPropagation() {
    int lgK = 4;
    int k = 1 << lgK;
    int u = 10 * k;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    assertTrue(local.isEmpty());
    // for internal checks
    ConcurrentHeapThetaBuffer sk1 = (ConcurrentHeapThetaBuffer) local;
    int i = 0;
    for (; i < k; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    assertFalse(local.isEmpty());
    assertTrue(local.getEstimate() > 0.0);
    long theta1 = ((ConcurrentSharedThetaSketch) shared).getVolatileTheta();
    for (; i < u; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    long theta2 = ((ConcurrentSharedThetaSketch) shared).getVolatileTheta();
    int entries = shared.getRetainedEntries(false);
    assertTrue((entries > k) || (theta2 < theta1), "entries=" + entries + " k=" + k + " theta1=" + theta1 + " theta2=" + theta2);
    shared.rebuild();
    assertEquals(shared.getRetainedEntries(false), k);
    assertEquals(shared.getRetainedEntries(true), k);
    sk1.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 17 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkDirectCompactConversion.

@Test
public void checkDirectCompactConversion() {
    int lgK = 9;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    assertTrue(sl.shared instanceof ConcurrentDirectQuickSelectSketch);
    assertTrue(sl.shared.compact().isCompact());
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 18 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkEstMode.

@Test
public void checkEstMode() {
    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);
    assertTrue(shared.getRetainedEntries(false) > k);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 19 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkWrapMemoryEst.

@Test
public void checkWrapMemoryEst() {
    int lgK = 9;
    int k = 1 << lgK;
    int u = 2 * k;
    boolean estimating = (u > k);
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    for (int i = 0; i < u; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    double sk1est = local.getEstimate();
    double sk1lb = local.getLowerBound(2);
    double sk1ub = local.getUpperBound(2);
    assertEquals(local.isEstimationMode(), estimating);
    Sketch local2 = Sketch.wrap(sl.wmem);
    assertEquals(local2.getEstimate(), sk1est);
    assertEquals(local2.getLowerBound(2), sk1lb);
    assertEquals(local2.getUpperBound(2), sk1ub);
    assertEquals(local2.isEmpty(), false);
    assertEquals(local2.isEstimationMode(), estimating);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 20 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkHeapifyMemoryEstimating.

@Test
public void checkHeapifyMemoryEstimating() {
    int lgK = 9;
    int k = 1 << lgK;
    int u = 2 * k;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    // off-heap
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    for (int i = 0; i < u; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    assertEquals(shared.getClass().getSimpleName(), "ConcurrentDirectQuickSelectSketch");
    assertEquals(local.getClass().getSimpleName(), "ConcurrentHeapThetaBuffer");
    // This sharedHeap is not linked to the concurrent local buffer
    UpdateSketch sharedHeap = Sketches.heapifyUpdateSketch(sl.wmem);
    assertEquals(sharedHeap.getClass().getSimpleName(), "HeapQuickSelectSketch");
    checkMemoryDirectProxyMethods(local, shared);
    checkOtherProxyMethods(local, shared);
    checkOtherProxyMethods(local, sharedHeap);
    int curCount1 = shared.getRetainedEntries(true);
    int curCount2 = sharedHeap.getRetainedEntries(true);
    assertEquals(curCount1, curCount2);
    long[] cache = sharedHeap.getCache();
    long thetaLong = sharedHeap.getThetaLong();
    int cacheCount = HashOperations.count(cache, thetaLong);
    assertEquals(curCount1, cacheCount);
    assertEquals(local.getCurrentPreambleLongs(), 3);
}
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