Search in sources :

Example 1 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkConstructReconstructFromMemory.

@Test
public void checkConstructReconstructFromMemory() {
    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;
    // force estimation
    for (int i = 0; i < u; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    double est1 = local.getEstimate();
    int count1 = shared.getRetainedEntries(false);
    assertTrue((est1 < (u * 1.05)) && (est1 > (u * 0.95)));
    assertTrue(count1 >= k);
    byte[] serArr;
    double est2;
    serArr = shared.toByteArray();
    WritableMemory mem = WritableMemory.writableWrap(serArr);
    UpdateSketch recoveredShared = Sketches.wrapUpdateSketch(mem);
    // reconstruct to Native/Direct
    final int bytes = Sketch.getMaxUpdateSketchBytes(k);
    final WritableMemory wmem = WritableMemory.allocate(bytes);
    shared = sl.bldr.buildSharedFromSketch(recoveredShared, wmem);
    UpdateSketch local2 = sl.bldr.buildLocal(shared);
    est2 = local2.getEstimate();
    assertEquals(est2, est1, 0.0);
}
Also used : WritableMemory(org.apache.datasketches.memory.WritableMemory) SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 2 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkHeapifySeedConflict.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifySeedConflict() {
    int lgK = 9;
    long seed1 = 1021;
    long seed2 = DEFAULT_UPDATE_SEED;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, seed1, useMem, true, 1);
    UpdateSketch shared = sl.shared;
    Memory srcMem = Memory.wrap(shared.toByteArray());
    Sketch.heapify(srcMem, seed2);
}
Also used : Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 3 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkBadSerVer.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadSerVer() {
    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());
    for (int i = 0; i < k; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    assertFalse(local.isEmpty());
    assertEquals(local.getEstimate(), k, 0.0);
    assertEquals(shared.getRetainedEntries(false), k);
    // corrupt the SerVer byte
    sl.wmem.putByte(SER_VER_BYTE, (byte) 0);
    Sketch.wrap(sl.wmem);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 4 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkBadLgNomLongs.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadLgNomLongs() {
    int lgK = 4;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    // Corrupt LgNomLongs byte
    sl.wmem.putByte(LG_NOM_LONGS_BYTE, (byte) 3);
    DirectQuickSelectSketch.writableWrap(sl.wmem, DEFAULT_UPDATE_SEED);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 5 with SharedLocal

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

the class ConcurrentDirectQuickSelectSketchTest method checkErrorBounds.

@Test
public void checkErrorBounds() {
    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;
    // Exact mode
    for (int i = 0; i < k; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    double est = local.getEstimate();
    double lb = local.getLowerBound(2);
    double ub = local.getUpperBound(2);
    assertEquals(est, ub, 0.0);
    assertEquals(est, lb, 0.0);
    // Est mode
    int u = 100 * k;
    for (int i = k; i < u; i++) {
        local.update(i);
        // test duplicate rejection
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    est = local.getEstimate();
    lb = local.getLowerBound(2);
    ub = local.getUpperBound(2);
    assertTrue(est <= ub);
    assertTrue(est >= lb);
}
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