Search in sources :

Example 6 with LargeStringInputStream

use of org.vertexium.test.util.LargeStringInputStream in project vertexium by visallo.

the class GraphTestBase method testStreamingPropertyValueResetMutlipleLargeReadsUntilEnd.

@Test
public void testStreamingPropertyValueResetMutlipleLargeReadsUntilEnd() throws IOException {
    assumeTrue("InputStream mark/reset is not supported", isInputStreamMarkResetSupported());
    String expectedLargeValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE));
    byte[] expectedLargeValueBytes = expectedLargeValue.getBytes();
    PropertyValue propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedLargeValue.getBytes()), String.class);
    graph.prepareVertex("v1", VISIBILITY_A).setProperty("propLarge", propLarge, VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
    graph.flush();
    Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
    StreamingPropertyValue prop = (StreamingPropertyValue) v1.getPropertyValue("propLarge");
    InputStream in = prop.getInputStream();
    in.mark(2);
    for (int i = 0; i < 3; i++) {
        int totalBytesRead = 0;
        while (in.read() >= 0) {
            totalBytesRead++;
            assertTrue("Read past end of input stream", totalBytesRead <= expectedLargeValueBytes.length);
        }
        assertEquals("Read unexpected number of bytes on loop: " + i, expectedLargeValueBytes.length, totalBytesRead);
        assertEquals(-1, in.read());
        in.reset();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) LargeStringInputStream(org.vertexium.test.util.LargeStringInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PropertyValue(org.vertexium.property.PropertyValue) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) IndexHint(org.vertexium.search.IndexHint) LargeStringInputStream(org.vertexium.test.util.LargeStringInputStream)

Example 7 with LargeStringInputStream

use of org.vertexium.test.util.LargeStringInputStream in project vertexium by visallo.

the class GraphTestBase method testStreamingPropertyDecreasingSize.

@Test
public void testStreamingPropertyDecreasingSize() throws IOException {
    Metadata metadata = new Metadata();
    Long timestamp = System.currentTimeMillis();
    String expectedValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE));
    PropertyValue propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedValue.getBytes()), String.class, (long) expectedValue.length());
    graph.prepareVertex("v1", VISIBILITY_A).addPropertyValue("key1", "largeProp", propLarge, metadata, timestamp, VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
    graph.flush();
    Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B);
    StreamingPropertyValue spv = (StreamingPropertyValue) v1.getPropertyValue("key1", "largeProp");
    assertEquals(expectedValue, spv.readToString());
    // now save a smaller value, making sure it gets truncated
    expectedValue = "small";
    propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedValue.getBytes()), String.class, (long) expectedValue.length());
    graph.prepareVertex("v1", VISIBILITY_A).addPropertyValue("key1", "largeProp", propLarge, metadata, timestamp + 1, VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
    graph.flush();
    v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B);
    spv = (StreamingPropertyValue) v1.getPropertyValue("key1", "largeProp");
    assertEquals(expectedValue, spv.readToString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) PropertyValue(org.vertexium.property.PropertyValue) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) LargeStringInputStream(org.vertexium.test.util.LargeStringInputStream)

Aggregations

StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)7 LargeStringInputStream (org.vertexium.test.util.LargeStringInputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 PropertyValue (org.vertexium.property.PropertyValue)6 InputStream (java.io.InputStream)3 IndexHint (org.vertexium.search.IndexHint)3 Test (org.junit.Test)1 InMemoryGraph (org.vertexium.inmemory.InMemoryGraph)1