ElementSerialisation { public Properties getPropertiesFromTimestamp(final String group, final long timestamp) throws SerialisationException { final SchemaElementDefinition elementDefinition = schema.getElement(group); if (null == elementDefinition) { throw new SerialisationException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?"); } final Properties properties = new Properties(); if (null != timestampProperty && elementDefinition.containsProperty(timestampProperty)) { properties.put(timestampProperty, timestamp); } return properties; } ElementSerialisation(final Schema schema); byte[] getValue(final Element element); byte[] getValue(final String group, final Properties properties); Properties getPropertiesFromValue(final String group, final byte[] value); Element getPartialElement(final String group, final byte[] rowId, final boolean includeMatchedVertex); Element getElement(final Cell cell, final boolean includeMatchedVertex); Properties getProperties(final String group, final Cell cell); byte[] getColumnVisibility(final Element element); byte[] getColumnVisibility(final String group, final Properties properties); byte[] getColumnQualifier(final Element element); byte[] getColumnQualifier(final String group, final Properties properties); Properties getPropertiesFromColumnQualifier(final String group, final byte[] bytes); byte[] getPropertiesAsBytesFromColumnQualifier(final String group, final byte[] bytes, final int numProps); long getTimestamp(final Element element); long getTimestamp(final Properties properties); Properties getPropertiesFromTimestamp(final String group, final long timestamp); byte[] serialiseVertex(final Object vertex); boolean isEntity(final Cell cell); String getGroup(final Cell cell); String getGroup(final byte[] columnQualifier); @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Entity it must be an Edge") Pair<byte[], byte[]> getRowKeys(final Element element); byte[] getRowKey(final Entity entity); Pair<byte[], byte[]> getRowKeys(final Edge edge); Pair<Cell, Cell> getCells(final Element element, final CellCreator kvCreator); Pair<Cell, Cell> getCells(final Element element, final Pair<byte[], byte[]> row, final byte[] cq, final CellCreator kvCreator); Pair<Put, Put> getPuts(final Element element); Pair<Put, Put> getPuts(final Element element, final Pair<byte[], byte[]> row, final byte[] cq); EdgeDirection getSourceAndDestination(final byte[] rowKey, final byte[][] sourceDestValues);  }
@Test public void shouldGetPropertiesFromTimestamp() throws Exception { final Schema schema = new Schema.Builder().json(StreamUtil.schemas(getClass())).build(); serialisation = new ElementSerialisation(new Schema.Builder(schema) .type("timestamp", Long.class) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .property(HBasePropertyNames.TIMESTAMP, "timestamp") .build()) .config(HBaseStoreConstants.TIMESTAMP_PROPERTY, TestPropertyNames.TIMESTAMP) .build()); final long timestamp = System.currentTimeMillis(); final String group = TestGroups.EDGE; final Properties properties = serialisation.getPropertiesFromTimestamp(group, timestamp); assertEquals(1, properties.size()); assertEquals(timestamp, properties.get(HBasePropertyNames.TIMESTAMP)); }
@Test public void shouldGetEmptyPropertiesFromTimestampWhenNoTimestampPropertyInGroup() throws Exception { final Schema schema = new Schema.Builder().json(StreamUtil.schemas(getClass())).build(); serialisation = new ElementSerialisation(new Schema.Builder(schema) .config(HBaseStoreConstants.TIMESTAMP_PROPERTY, TestPropertyNames.TIMESTAMP) .build()); final long timestamp = System.currentTimeMillis(); final String group = TestGroups.EDGE; final Properties properties = serialisation.getPropertiesFromTimestamp(group, timestamp); assertEquals(0, properties.size()); }
@Test public void shouldGetEmptyPropertiesFromTimestampWhenNoTimestampProperty() throws Exception { final long timestamp = System.currentTimeMillis(); final String group = TestGroups.EDGE; final Properties properties = serialisation.getPropertiesFromTimestamp(group, timestamp); assertEquals(0, properties.size()); }
@Test public void shouldThrowExceptionWhenGetPropertiesFromTimestampWhenGroupIsNotFound() { final long timestamp = System.currentTimeMillis(); final String group = "unknownGroup"; try { serialisation.getPropertiesFromTimestamp(group, timestamp); fail("Exception expected"); } catch (final Exception e) { assertNotNull(e.getMessage()); } }