Search in sources :

Example 26 with WritableMemory

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

the class HeapUnionTest method checkUpdateMemorySpecialCases2.

@Test
public void checkUpdateMemorySpecialCases2() {
    //4096
    int lgK = 12;
    int k = 1 << lgK;
    int u = 2 * k;
    UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
    //force prelongs to 3
    for (int i = 0; i < u; i++) usk1.update(i);
    CompactSketch usk1c = usk1.compact(true, null);
    WritableMemory v3mem1 = WritableMemory.wrap(usk1c.toByteArray());
    //println(PreambleUtil.toString(v3mem1));
    Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
    union.update(v3mem1);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 27 with WritableMemory

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

the class HeapUnionTest method checkMemBadSerVer.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkMemBadSerVer() {
    //4096
    int lgK = 12;
    int k = 1 << lgK;
    UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
    CompactSketch usk1c = usk1.compact(true, null);
    WritableMemory v3mem1 = WritableMemory.wrap(usk1c.toByteArray());
    //corrupt SerVer
    v3mem1.putByte(SER_VER_BYTE, (byte) 0);
    Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
    union.update(v3mem1);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 28 with WritableMemory

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

the class SetOperationTest method checkIsSameResource.

@Test
public void checkIsSameResource() {
    int k = 16;
    WritableMemory mem = WritableMemory.wrap(new byte[(k * 16) + 32]);
    Memory cmem = Memory.wrap(new byte[8]);
    Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion(mem);
    assertTrue(union.isSameResource(mem));
    assertFalse(union.isSameResource(cmem));
    Intersection inter = Sketches.setOperationBuilder().buildIntersection(mem);
    assertTrue(inter.isSameResource(mem));
    assertFalse(inter.isSameResource(cmem));
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 29 with WritableMemory

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

the class SetOperationTest method checkBuilderAnotB_noMem.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBuilderAnotB_noMem() {
    WritableMemory mem = WritableMemory.wrap(new byte[64]);
    SetOperation.builder().build(Family.A_NOT_B, mem);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 30 with WritableMemory

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

the class SketchTest method checkHeapifyQSCompactExcep.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifyQSCompactExcep() {
    int k = 512;
    Sketch sketch1 = UpdateSketch.builder().setFamily(QUICKSELECT).setNominalEntries(k).build();
    byte[] byteArray = sketch1.toByteArray();
    WritableMemory mem = WritableMemory.wrap(byteArray);
    //corrupt:
    mem.setBits(FLAGS_BYTE, (byte) COMPACT_FLAG_MASK);
    Sketch.heapify(mem);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

WritableMemory (com.yahoo.memory.WritableMemory)264 Test (org.testng.annotations.Test)210 Memory (com.yahoo.memory.Memory)34 SketchesArgumentException (com.yahoo.sketches.SketchesArgumentException)15 ArrayOfLongsSerDe (com.yahoo.sketches.ArrayOfLongsSerDe)11 ArrayOfStringsSerDe (com.yahoo.sketches.ArrayOfStringsSerDe)6 WritableDirectHandle (com.yahoo.memory.WritableDirectHandle)5 MemoryRequestServer (com.yahoo.memory.MemoryRequestServer)2 ArrayOfDoublesSerDe (com.yahoo.sketches.ArrayOfDoublesSerDe)2 ArrayOfNumbersSerDe (com.yahoo.sketches.ArrayOfNumbersSerDe)2 PreambleUtil.extractTgtHllType (com.yahoo.sketches.hll.PreambleUtil.extractTgtHllType)2 ResizeFactor (com.yahoo.sketches.ResizeFactor)1 PreambleUtil.extractCurMode (com.yahoo.sketches.hll.PreambleUtil.extractCurMode)1 PreambleUtil.insertTgtHllType (com.yahoo.sketches.hll.PreambleUtil.insertTgtHllType)1 Util.checkIsCompactMemory (com.yahoo.sketches.quantiles.Util.checkIsCompactMemory)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ByteBuffer (java.nio.ByteBuffer)1