use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class HllUtil method checkPreamble.
static CurMode checkPreamble(final Memory mem) {
final int preInts = extractPreInts(mem);
final int serVer = extractSerVer(mem);
final int famId = extractFamilyId(mem);
final CurMode curMode = extractCurMode(mem);
if ((famId != Family.HLL.getID()) || (serVer != 1) || ((preInts != LIST_PREINTS) && (preInts != HASH_SET_PREINTS) && (preInts != HLL_PREINTS)) || ((curMode == CurMode.LIST) && (preInts != LIST_PREINTS)) || ((curMode == CurMode.SET) && (preInts != HASH_SET_PREINTS)) || ((curMode == CurMode.HLL) && (preInts != HLL_PREINTS))) {
throw new SketchesArgumentException("Possible Corruption, Invalid Preamble:" + PreambleUtil.toString(mem));
}
return curMode;
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class DirectUpdateDoublesSketch method growCombinedMemBuffer.
// Direct supporting methods
private WritableMemory growCombinedMemBuffer(final int itemSpaceNeeded) {
final long memBytes = mem_.getCapacity();
// + preamble + min & max
final int needBytes = (itemSpaceNeeded << 3) + COMBINED_BUFFER;
assert needBytes > memBytes;
memReqSvr = (memReqSvr == null) ? mem_.getMemoryRequestServer() : memReqSvr;
if (memReqSvr == null) {
throw new SketchesArgumentException("A request for more memory has been denied, " + "or a default MemoryRequestServer has not been provided. Must abort. ");
}
final WritableMemory newMem = memReqSvr.request(mem_, needBytes);
mem_.copyTo(0, newMem, 0, memBytes);
memReqSvr.requestClose(mem_, newMem);
return newMem;
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class ReservoirItemsSketchTest method checkBadMemory.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadMemory() {
byte[] bytes = new byte[4];
Memory mem = Memory.wrap(bytes);
try {
PreambleUtil.getAndCheckPreLongs(mem);
fail();
} catch (final SketchesArgumentException e) {
// expected
}
bytes = new byte[8];
// only 1 preLong worth of items in bytearray
bytes[0] = 2;
mem = Memory.wrap(bytes);
PreambleUtil.getAndCheckPreLongs(mem);
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class ReservoirItemsSketchTest method checkArrayOfNumbersSerDeErrors.
@Test
public void checkArrayOfNumbersSerDeErrors() {
// Highly debatable whether this belongs here vs a stand-alone test class
final ReservoirItemsSketch<Number> ris = ReservoirItemsSketch.newInstance(6);
assertNull(ris.getSamples());
assertNull(ris.getSamples(Number.class));
// using mixed types, but BigDecimal not supported by serde class
ris.update(1);
ris.update(new BigDecimal(2));
// this should work since BigDecimal is an instance of Number
final Number[] data = ris.getSamples(Number.class);
assertNotNull(data);
assertEquals(data.length, 2);
// toByteArray() should fail
final ArrayOfNumbersSerDe serDe = new ArrayOfNumbersSerDe();
try {
ris.toByteArray(serDe, Number.class);
fail();
} catch (final SketchesArgumentException e) {
// expected
}
// force entry to a supported type
data[1] = 3.0;
final byte[] bytes = serDe.serializeToByteArray(data);
// change first element to indicate something unsupported
bytes[0] = 'q';
try {
serDe.deserializeFromMemory(Memory.wrap(bytes), 2);
fail();
} catch (final SketchesArgumentException e) {
// expected
}
}
use of org.apache.datasketches.SketchesArgumentException in project sketches-core by DataSketches.
the class VarOptItemsSketchTest method checkBadMemory.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadMemory() {
byte[] bytes = new byte[4];
Memory mem = Memory.wrap(bytes);
try {
PreambleUtil.getAndCheckPreLongs(mem);
fail();
} catch (final SketchesArgumentException e) {
// expected
}
bytes = new byte[8];
// only 1 preLong worth of items in bytearray
bytes[0] = 2;
mem = Memory.wrap(bytes);
PreambleUtil.getAndCheckPreLongs(mem);
}
Aggregations