use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class DirectHllSketchTest method checkPutKxQ1_Misc.
@Test
public void checkPutKxQ1_Misc() {
int bytes = HllSketch.getMaxUpdatableSerializationBytes(4, TgtHllType.HLL_4);
WritableMemory wmem = WritableMemory.allocate(bytes);
HllSketch sk = new HllSketch(4, TgtHllType.HLL_4, wmem);
for (int i = 0; i < 8; i++) {
sk.update(i);
}
assertTrue(sk.getCurMode() == CurMode.HLL);
AbstractHllArray absArr = (AbstractHllArray) sk.hllSketchImpl;
absArr.putKxQ1(1.0);
assertEquals(absArr.getKxQ1(), 1.0);
absArr.putKxQ1(0.0);
Memory mem = wmem;
HllSketch sk2 = HllSketch.wrap(mem);
try {
sk2.reset();
fail();
} catch (SketchesArgumentException e) {
// expected
}
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class PreambleUtilTest method checkStreamErrors.
@Test
public void checkStreamErrors() {
WritableMemory wmem = WritableMemory.allocate(4 * 10);
putEmptyMerged(wmem, (byte) 12, defaultSeedHash);
try {
getSvStreamOffset(wmem);
fail();
} catch (SketchesArgumentException e) {
}
wmem.putByte(5, (byte) (7 << 2));
try {
getSvStreamOffset(wmem);
fail();
} catch (SketchesStateException e) {
}
wmem.putByte(5, (byte) 0);
try {
getWStreamOffset(wmem);
fail();
} catch (SketchesArgumentException e) {
}
wmem.putByte(5, (byte) (7 << 2));
try {
getWStreamOffset(wmem);
fail();
} catch (SketchesStateException e) {
}
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class HllSketchTest method checkCompact.
// Creates either a direct or heap sketch,
// Serializes to either compact or updatable form.
// Confirms the isMemory() for direct, isOffHeap(), and the
// get compact or updatable serialization bytes.
// Returns true if the compact flag is set.
private static boolean checkCompact(int lgK, int n, TgtHllType type, boolean direct, boolean compact) {
int bytes = HllSketch.getMaxUpdatableSerializationBytes(lgK, type);
WritableMemory wmem = WritableMemory.allocate(bytes);
HllSketch sk = (direct) ? new HllSketch(lgK, type, wmem) : new HllSketch(lgK, type);
assertEquals(sk.isMemory(), direct);
assertFalse(sk.isOffHeap());
// LOAD
for (int i = 0; i < n; i++) {
sk.update(i);
}
byte[] byteArr = (compact) ? sk.toCompactByteArray() : sk.toUpdatableByteArray();
int len = byteArr.length;
if (compact) {
assertEquals(len, sk.getCompactSerializationBytes());
} else {
assertEquals(len, sk.getUpdatableSerializationBytes());
}
HllSketch sk2 = HllSketch.wrap(Memory.wrap(byteArr));
assertEquals(sk2.getEstimate(), n, .01);
boolean resourceCompact = sk2.isCompact();
if (resourceCompact) {
try {
HllSketch.writableWrap(WritableMemory.writableWrap(byteArr));
fail();
} catch (SketchesArgumentException e) {
// OK
}
}
return resourceCompact;
// return (byteArr[5] & COMPACT_FLAG_MASK) > 0;
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class ItemsSketchTest method tryBadMem.
// Restricted methods
private static void tryBadMem(WritableMemory mem, int byteOffset, int byteValue) {
ArrayOfLongsSerDe serDe = new ArrayOfLongsSerDe();
try {
// Corrupt
mem.putByte(byteOffset, (byte) byteValue);
ItemsSketch.getInstance(mem, serDe);
fail();
} catch (SketchesArgumentException e) {
// expected
}
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class DoublesUnionImplTest method checkResultViaMemory.
@Test
public void checkResultViaMemory() {
// empty gadget
final DoublesUnion union = DoublesUnion.builder().build();
// memory too small
WritableMemory mem = WritableMemory.allocate(1);
try {
union.getResult(mem);
fail();
} catch (final SketchesArgumentException e) {
// expected
}
// sufficient memory
mem = WritableMemory.allocate(8);
DoublesSketch result = union.getResult(mem);
assertTrue(result.isEmpty());
final int k = 128;
final int n = 1392;
mem = WritableMemory.allocate(DoublesSketch.getUpdatableStorageBytes(k, n));
final DoublesSketch qs = buildAndLoadQS(k, n);
union.update(qs);
result = union.getResult(mem);
DoublesSketchTest.testSketchEquality(result, qs);
}
Aggregations