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);
}
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);
}
Aggregations