use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.
the class ConcurrentDirectQuickSelectSketchTest method checkDQStoCompactForms.
@Test
public void checkDQStoCompactForms() {
int lgK = 9;
int k = 1 << lgK;
int u = 4 * k;
boolean estimating = (u > k);
boolean useMem = true;
SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
UpdateSketch shared = sl.shared;
UpdateSketch local = sl.local;
assertEquals(local.getClass().getSimpleName(), "ConcurrentHeapThetaBuffer");
assertFalse(local.isDirect());
assertTrue(local.hasMemory());
for (int i = 0; i < u; i++) {
local.update(i);
}
waitForBgPropagationToComplete(shared);
// forces size back to k
shared.rebuild();
// get baseline values
double localEst = local.getEstimate();
double localLB = local.getLowerBound(2);
double localUB = local.getUpperBound(2);
assertEquals(local.isEstimationMode(), estimating);
CompactSketch csk;
csk = shared.compact(false, null);
assertEquals(csk.getEstimate(), localEst);
assertEquals(csk.getLowerBound(2), localLB);
assertEquals(csk.getUpperBound(2), localUB);
assertFalse(csk.isEmpty());
assertEquals(csk.isEstimationMode(), estimating);
assertEquals(csk.getClass().getSimpleName(), "HeapCompactSketch");
csk = shared.compact(true, null);
assertEquals(csk.getEstimate(), localEst);
assertEquals(csk.getLowerBound(2), localLB);
assertEquals(csk.getUpperBound(2), localUB);
assertFalse(csk.isEmpty());
assertEquals(csk.isEstimationMode(), estimating);
assertEquals(csk.getClass().getSimpleName(), "HeapCompactSketch");
int bytes = shared.getCompactBytes();
assertEquals(bytes, (k * 8) + (Family.COMPACT.getMaxPreLongs() << 3));
byte[] memArr2 = new byte[bytes];
WritableMemory mem2 = WritableMemory.writableWrap(memArr2);
csk = shared.compact(false, mem2);
assertEquals(csk.getEstimate(), localEst);
assertEquals(csk.getLowerBound(2), localLB);
assertEquals(csk.getUpperBound(2), localUB);
assertFalse(csk.isEmpty());
assertEquals(csk.isEstimationMode(), estimating);
assertEquals(csk.getClass().getSimpleName(), "DirectCompactSketch");
mem2.clear();
csk = shared.compact(true, mem2);
assertEquals(csk.getEstimate(), localEst);
assertEquals(csk.getLowerBound(2), localLB);
assertEquals(csk.getUpperBound(2), localUB);
assertFalse(csk.isEmpty());
assertEquals(csk.isEstimationMode(), estimating);
assertEquals(csk.getClass().getSimpleName(), "DirectCompactSketch");
csk.toString(false, true, 0, false);
}
use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.
the class ConcurrentDirectQuickSelectSketchTest method checkWrapIllegalFamilyID_wrap.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkWrapIllegalFamilyID_wrap() {
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
// catch in Sketch.constructDirectSketch
Sketch.wrap(sl.wmem);
}
use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.
the class ConcurrentDirectQuickSelectSketchTest method checkCorruptLgNomLongs.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkCorruptLgNomLongs() {
int lgK = 4;
boolean useMem = true;
SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
// corrupt
sl.wmem.putByte(LG_NOM_LONGS_BYTE, (byte) 2);
Sketch.heapify(sl.wmem, DEFAULT_UPDATE_SEED);
}
use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.
the class ConcurrentDirectQuickSelectSketchTest method checkUpperAndLowerBounds.
@Test
public void checkUpperAndLowerBounds() {
int lgK = 9;
int k = 1 << lgK;
int u = 2 * 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 est = local.getEstimate();
double ub = local.getUpperBound(1);
double lb = local.getLowerBound(1);
assertTrue(ub > est);
assertTrue(lb < est);
}
use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.
the class ConcurrentDirectQuickSelectSketchTest method checkHeapifyIllegalFamilyID_heapify.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifyIllegalFamilyID_heapify() {
int lgK = 9;
boolean useMem = true;
SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
// corrupt the Family ID byte
sl.wmem.putByte(FAMILY_BYTE, (byte) 0);
// try to heapify the corrupted mem
// catch in Sketch.constructHeapSketch
Sketch.heapify(sl.wmem);
}
Aggregations