Search in sources :

Example 6 with SketchesReadOnlyException

use of com.yahoo.sketches.SketchesReadOnlyException in project sketches-core by DataSketches.

the class ReadOnlyMemoryTest method wrapEmptyUpdateSketch.

@Test
public void wrapEmptyUpdateSketch() {
    final UpdateDoublesSketch s1 = DoublesSketch.builder().build();
    final Memory mem = Memory.wrap(s1.toByteArray());
    UpdateDoublesSketch s2 = (UpdateDoublesSketch) DoublesSketch.wrap(mem);
    Assert.assertTrue(s2.isEmpty());
    // ensure the various put calls fail
    try {
        s2.putMinValue(-1.0);
        fail();
    } catch (final SketchesReadOnlyException e) {
    // expected
    }
    try {
        s2.putMaxValue(1.0);
        fail();
    } catch (final SketchesReadOnlyException e) {
    // expected
    }
    try {
        s2.putN(1);
        fail();
    } catch (final SketchesReadOnlyException e) {
    // expected
    }
    try {
        s2.putBitPattern(1);
        fail();
    } catch (final SketchesReadOnlyException e) {
    // expected
    }
    try {
        s2.reset();
        fail();
    } catch (final SketchesReadOnlyException e) {
    // expected
    }
    try {
        s2.putBaseBufferCount(5);
        fail();
    } catch (final SketchesReadOnlyException e) {
    // expected
    }
    try {
        s2.putCombinedBuffer(new double[16]);
        fail();
    } catch (final SketchesReadOnlyException e) {
    // expected
    }
    try {
        final int currCap = s2.getCombinedBufferItemCapacity();
        s2.growCombinedBuffer(currCap, 2 * currCap);
        fail();
    } catch (final SketchesReadOnlyException e) {
    // expected
    }
}
Also used : Memory(com.yahoo.memory.Memory) SketchesReadOnlyException(com.yahoo.sketches.SketchesReadOnlyException) Test(org.testng.annotations.Test)

Aggregations

Memory (com.yahoo.memory.Memory)6 SketchesReadOnlyException (com.yahoo.sketches.SketchesReadOnlyException)6 Test (org.testng.annotations.Test)6