Search in sources :

Example 11 with SketchesReadOnlyException

use of org.apache.datasketches.SketchesReadOnlyException in project sketches-core by DataSketches.

the class ReadOnlyMemoryTest method wrapIntersection.

@Test
public void wrapIntersection() {
    UpdateSketch us1 = UpdateSketch.builder().build();
    us1.update(1);
    us1.update(2);
    UpdateSketch us2 = UpdateSketch.builder().build();
    us2.update(2);
    us2.update(3);
    Intersection i1 = SetOperation.builder().buildIntersection();
    i1.intersect(us1);
    i1.intersect(us2);
    Memory mem = Memory.wrap(ByteBuffer.wrap(i1.toByteArray()).asReadOnlyBuffer().order(ByteOrder.nativeOrder()));
    Intersection i2 = (Intersection) SetOperation.wrap(mem);
    Assert.assertEquals(i2.getResult().getEstimate(), 1.0);
    boolean thrown = false;
    try {
        i2.intersect(us1);
    } catch (SketchesReadOnlyException e) {
        thrown = true;
    }
    Assert.assertTrue(thrown);
}
Also used : Memory(org.apache.datasketches.memory.Memory) SketchesReadOnlyException(org.apache.datasketches.SketchesReadOnlyException) Test(org.testng.annotations.Test)

Example 12 with SketchesReadOnlyException

use of org.apache.datasketches.SketchesReadOnlyException in project sketches-core by DataSketches.

the class ReadOnlyMemoryTest method wrapAndTryUpdatingSketch.

@Test
public void wrapAndTryUpdatingSketch() {
    final ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().build();
    sketch1.update(1, new double[] { 1 });
    final ArrayOfDoublesUpdatableSketch sketch2 = (ArrayOfDoublesUpdatableSketch) ArrayOfDoublesSketches.wrapSketch(Memory.wrap(sketch1.toByteArray()));
    Assert.assertEquals(sketch2.getEstimate(), 1.0);
    sketch2.toByteArray();
    boolean thrown = false;
    try {
        sketch2.update(2, new double[] { 1 });
    } catch (final SketchesReadOnlyException e) {
        thrown = true;
    }
    try {
        sketch2.trim();
    } catch (final SketchesReadOnlyException e) {
        thrown = true;
    }
    Assert.assertTrue(thrown);
}
Also used : ArrayOfDoublesUpdatableSketchBuilder(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketchBuilder) ArrayOfDoublesUpdatableSketch(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketch) SketchesReadOnlyException(org.apache.datasketches.SketchesReadOnlyException) Test(org.testng.annotations.Test)

Aggregations

SketchesReadOnlyException (org.apache.datasketches.SketchesReadOnlyException)12 Test (org.testng.annotations.Test)10 Memory (org.apache.datasketches.memory.Memory)8 WritableMemory (org.apache.datasketches.memory.WritableMemory)3 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)2 ArrayOfDoublesUpdatableSketch (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketch)2 ArrayOfDoublesUpdatableSketchBuilder (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketchBuilder)2 WritableHandle (org.apache.datasketches.memory.WritableHandle)1 ArrayOfDoublesSetOperationBuilder (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSetOperationBuilder)1 ArrayOfDoublesSketch (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch)1 ArrayOfDoublesUnion (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUnion)1