use of org.vertexium.property.PropertyValue 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();
}
}
use of org.vertexium.property.PropertyValue 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());
}
use of org.vertexium.property.PropertyValue in project vertexium by visallo.
the class GraphTestBase method testStreamingPropertyValueMarkReset.
@Test
public void testStreamingPropertyValueMarkReset() throws IOException {
assumeTrue("InputStream mark/reset is not supported", isInputStreamMarkResetSupported());
String expectedLargeValue = "abcdefghijk";
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();
byte[] buffer = new byte[15];
int sizeRead = in.read(buffer);
assertEquals(11, sizeRead);
assertEquals("abcdefghijk", new String(buffer, 0, sizeRead));
in.reset();
buffer = new byte[3];
sizeRead = in.read(buffer);
assertEquals(3, sizeRead);
assertEquals("abc", new String(buffer, 0, sizeRead));
assertEquals('d', (char) in.read());
assertEquals('e', (char) in.read());
in.mark(32);
buffer = new byte[5];
sizeRead = in.read(buffer);
assertEquals(5, sizeRead);
assertEquals("fghij", new String(buffer, 0, sizeRead));
in.reset();
buffer = new byte[10];
sizeRead = in.read(buffer);
assertEquals(6, sizeRead);
assertEquals("fghijk", new String(buffer, 0, sizeRead));
assertEquals(-1, in.read(buffer));
in.reset();
buffer = new byte[10];
sizeRead = in.read(buffer);
assertEquals(6, sizeRead);
assertEquals("fghijk", new String(buffer, 0, sizeRead));
}
Aggregations