Search in sources :

Example 1 with SketchesArgumentException

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
    }
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 2 with SketchesArgumentException

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) {
    }
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) WritableMemory(org.apache.datasketches.memory.WritableMemory) SketchesStateException(org.apache.datasketches.SketchesStateException) Test(org.testng.annotations.Test)

Example 3 with SketchesArgumentException

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;
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) WritableMemory(org.apache.datasketches.memory.WritableMemory)

Example 4 with SketchesArgumentException

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
    }
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) ArrayOfLongsSerDe(org.apache.datasketches.ArrayOfLongsSerDe)

Example 5 with SketchesArgumentException

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);
}
Also used : SketchesArgumentException(org.apache.datasketches.SketchesArgumentException) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)64 WritableMemory (org.apache.datasketches.memory.WritableMemory)38 Test (org.testng.annotations.Test)29 Family (org.apache.datasketches.Family)14 Memory (org.apache.datasketches.memory.Memory)13 Family.idToFamily (org.apache.datasketches.Family.idToFamily)10 SketchesReadOnlyException (org.apache.datasketches.SketchesReadOnlyException)7 WritableHandle (org.apache.datasketches.memory.WritableHandle)6 ResizeFactor (org.apache.datasketches.ResizeFactor)5 ArrayOfLongsSerDe (org.apache.datasketches.ArrayOfLongsSerDe)4 AnotbAction (org.apache.datasketches.SetOperationCornerCases.AnotbAction)3 CornerCase (org.apache.datasketches.SetOperationCornerCases.CornerCase)3 PreambleUtil.extractResizeFactor (org.apache.datasketches.sampling.PreambleUtil.extractResizeFactor)3 ArrayList (java.util.ArrayList)2 SketchesStateException (org.apache.datasketches.SketchesStateException)2 PreambleUtil.insertLgResizeFactor (org.apache.datasketches.theta.PreambleUtil.insertLgResizeFactor)2 UpdateSketch (org.apache.datasketches.theta.UpdateSketch)2 UpdateSketchBuilder (org.apache.datasketches.theta.UpdateSketchBuilder)2 BigDecimal (java.math.BigDecimal)1 ArrayOfBooleansSerDe (org.apache.datasketches.ArrayOfBooleansSerDe)1