Search in sources :

Example 6 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class GraphTestBase method testStreamingPropertyHistoricalVersions.

@Test
public void testStreamingPropertyHistoricalVersions() {
    Date time25 = createDate(2015, 4, 6, 16, 15, 0);
    Date time30 = createDate(2015, 4, 6, 16, 16, 0);
    Metadata metadata = new Metadata();
    StreamingPropertyValue value1 = StreamingPropertyValue.create("value1");
    graph.prepareVertex("v1", VISIBILITY_A).addPropertyValue("", "text", value1, metadata, time25.getTime(), VISIBILITY_A).save(AUTHORIZATIONS_A);
    StreamingPropertyValue value2 = StreamingPropertyValue.create("value2");
    graph.prepareVertex("v1", VISIBILITY_A).addPropertyValue("", "text", value2, metadata, time30.getTime(), VISIBILITY_A).save(AUTHORIZATIONS_A);
    graph.flush();
    Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
    List<HistoricalPropertyValue> values = toList(v1.getHistoricalPropertyValues("", "text", VISIBILITY_A, AUTHORIZATIONS_A));
    assertEquals(2, values.size());
    assertEquals("value2", ((StreamingPropertyValue) values.get(0).getValue()).readToString());
    assertEquals(time30, new Date(values.get(0).getTimestamp()));
    assertEquals("value1", ((StreamingPropertyValue) values.get(1).getValue()).readToString());
    assertEquals(time25, new Date(values.get(1).getTimestamp()));
    // make sure we get the correct age when we only ask for one value
    assertEquals("value2", ((StreamingPropertyValue) v1.getPropertyValue("", "text")).readToString());
}
Also used : StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue)

Example 7 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class GraphTestBase method testStreamingPropertyValueMarkResetLargeReads.

@Test
public void testStreamingPropertyValueMarkResetLargeReads() 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();
    int amountToRead = expectedLargeValueBytes.length - 8;
    byte[] buffer = null;
    while (amountToRead > 0) {
        buffer = new byte[amountToRead];
        amountToRead -= in.read(buffer);
    }
    assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 9), (char) buffer[buffer.length - 1]);
    in.mark(32);
    buffer = new byte[2];
    int sizeRead = in.read(buffer);
    assertEquals(2, sizeRead);
    assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 8), (char) buffer[0]);
    assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 7), (char) buffer[1]);
    assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 6), (char) in.read());
    in.reset();
    sizeRead = in.read(buffer);
    assertEquals(2, sizeRead);
    assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 8), (char) buffer[0]);
}
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 8 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class GraphTestBase method testAddStreamingPropertyValue.

@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
@Test
public void testAddStreamingPropertyValue() throws IOException, InterruptedException {
    String expectedLargeValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE));
    PropertyValue propSmall = StreamingPropertyValue.create(new ByteArrayInputStream("value1".getBytes()), String.class, 6L);
    PropertyValue propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedLargeValue.getBytes()), String.class, null);
    String largePropertyName = "propLarge/\\*!@#$%^&*()[]{}|";
    Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).setProperty("propSmall", propSmall, VISIBILITY_A).setProperty(largePropertyName, propLarge, VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
    graph.flush();
    Iterable<Object> propSmallValues = v1.getPropertyValues("propSmall");
    Assert.assertEquals(1, count(propSmallValues));
    Object propSmallValue = propSmallValues.iterator().next();
    assertTrue("propSmallValue was " + propSmallValue.getClass().getName(), propSmallValue instanceof StreamingPropertyValue);
    StreamingPropertyValue value = (StreamingPropertyValue) propSmallValue;
    assertEquals(String.class, value.getValueType());
    assertEquals("value1".getBytes().length, (long) value.getLength());
    assertEquals("value1", IOUtils.toString(value.getInputStream()));
    assertEquals("value1", IOUtils.toString(value.getInputStream()));
    Iterable<Object> propLargeValues = v1.getPropertyValues(largePropertyName);
    Assert.assertEquals(1, count(propLargeValues));
    Object propLargeValue = propLargeValues.iterator().next();
    assertTrue(largePropertyName + " was " + propLargeValue.getClass().getName(), propLargeValue instanceof StreamingPropertyValue);
    value = (StreamingPropertyValue) propLargeValue;
    assertEquals(String.class, value.getValueType());
    assertEquals(expectedLargeValue.getBytes().length, (long) value.getLength());
    assertEquals(expectedLargeValue, IOUtils.toString(value.getInputStream()));
    assertEquals(expectedLargeValue, IOUtils.toString(value.getInputStream()));
    graph.flush();
    v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
    propSmallValues = v1.getPropertyValues("propSmall");
    Assert.assertEquals(1, count(propSmallValues));
    propSmallValue = propSmallValues.iterator().next();
    assertTrue("propSmallValue was " + propSmallValue.getClass().getName(), propSmallValue instanceof StreamingPropertyValue);
    value = (StreamingPropertyValue) propSmallValue;
    assertEquals(String.class, value.getValueType());
    assertEquals("value1".getBytes().length, (long) value.getLength());
    assertEquals("value1", IOUtils.toString(value.getInputStream()));
    assertEquals("value1", IOUtils.toString(value.getInputStream()));
    propLargeValues = v1.getPropertyValues(largePropertyName);
    Assert.assertEquals(1, count(propLargeValues));
    propLargeValue = propLargeValues.iterator().next();
    assertTrue(largePropertyName + " was " + propLargeValue.getClass().getName(), propLargeValue instanceof StreamingPropertyValue);
    value = (StreamingPropertyValue) propLargeValue;
    assertEquals(String.class, value.getValueType());
    assertEquals(expectedLargeValue.getBytes().length, (long) value.getLength());
    assertEquals(expectedLargeValue, IOUtils.toString(value.getInputStream()));
    assertEquals(expectedLargeValue, IOUtils.toString(value.getInputStream()));
}
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)

Example 9 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class GraphTestBase method testStreamingPropertyValueLargeReads.

@Test
public void testStreamingPropertyValueLargeReads() throws IOException {
    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");
    byte[] buffer = new byte[LARGE_PROPERTY_VALUE_SIZE * 2];
    int leftToRead = expectedLargeValueBytes.length;
    InputStream in = prop.getInputStream();
    for (int expectedOffset = 0; expectedOffset < expectedLargeValueBytes.length; ) {
        int sizeRead = in.read(buffer);
        for (int j = 0; j < sizeRead; j++, expectedOffset++, leftToRead--) {
            assertEquals("invalid data at offset " + expectedOffset, expectedLargeValueBytes[expectedOffset], buffer[j]);
        }
    }
    assertEquals(0, leftToRead);
    assertEquals(-1, in.read(buffer));
}
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 10 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class GraphTestBase method testGetStreamingPropertyValueInputStreams.

@Test
public void testGetStreamingPropertyValueInputStreams() throws Exception {
    graph.defineProperty("a").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define();
    graph.defineProperty("b").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define();
    graph.defineProperty("c").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define();
    graph.prepareVertex("v1", VISIBILITY_A).setProperty("a", StreamingPropertyValue.create("Test Value A"), VISIBILITY_A).setProperty("b", StreamingPropertyValue.create("Test Value B"), VISIBILITY_A).setProperty("c", StreamingPropertyValue.create("Test Value C"), VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
    graph.flush();
    Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B);
    StreamingPropertyValue spvA = (StreamingPropertyValue) v1.getPropertyValue("a");
    assertEquals(12L, (long) spvA.getLength());
    StreamingPropertyValue spvB = (StreamingPropertyValue) v1.getPropertyValue("b");
    assertEquals(12L, (long) spvA.getLength());
    StreamingPropertyValue spvC = (StreamingPropertyValue) v1.getPropertyValue("c");
    assertEquals(12L, (long) spvA.getLength());
    ArrayList<StreamingPropertyValue> spvs = Lists.newArrayList(spvA, spvB, spvC);
    List<InputStream> streams = graph.getStreamingPropertyValueInputStreams(spvs);
    assertEquals("Test Value A", IOUtils.toString(streams.get(0)));
    assertEquals("Test Value B", IOUtils.toString(streams.get(1)));
    assertEquals("Test Value C", IOUtils.toString(streams.get(2)));
}
Also used : StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) LargeStringInputStream(org.vertexium.test.util.LargeStringInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)22 LargeStringInputStream (org.vertexium.test.util.LargeStringInputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)6 PropertyValue (org.vertexium.property.PropertyValue)6 Test (org.junit.Test)4 IndexHint (org.vertexium.search.IndexHint)4 Mutation (org.apache.accumulo.core.data.Mutation)3 Value (org.apache.accumulo.core.data.Value)3 DataTableRowKey (org.vertexium.accumulo.keys.DataTableRowKey)3 Text (org.apache.hadoop.io.Text)2 JSONObject (org.json.JSONObject)2 DeleteHistoricalLegacyStreamingPropertyValueData (org.vertexium.accumulo.tools.DeleteHistoricalLegacyStreamingPropertyValueData)2 VertexiumException (org.vertexium.VertexiumException)1 StreamingPropertyValueTableDataRef (org.vertexium.accumulo.StreamingPropertyValueTableDataRef)1 InMemoryGraph (org.vertexium.inmemory.InMemoryGraph)1 AlterPropertyVisibility (org.vertexium.mutation.AlterPropertyVisibility)1 ExtendedDataMutation (org.vertexium.mutation.ExtendedDataMutation)1 SetPropertyMetadata (org.vertexium.mutation.SetPropertyMetadata)1 MutablePropertyImpl (org.vertexium.property.MutablePropertyImpl)1