use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldDeserialiseEdgeId.
@Test
public void shouldDeserialiseEdgeId() {
// Given
final EdgeId expectedElementId = new EdgeSeed("source1", "dest1", true);
final Edge edge = new Edge.Builder().source("source1").dest("dest1").directed(true).group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
final Key key = converter.getKeysFromEdge(edge).getFirst();
// When
final ElementId elementId = converter.getElementId(key, false);
// Then
assertEquals(expectedElementId, elementId);
}
use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty.
@Test
public void shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty() {
// Given
final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("string").property(TestPropertyNames.PROP_1, "map").property(TestPropertyNames.PROP_2, "map").build()).type("string", String.class).type("map", new TypeDefinition.Builder().clazz(FreqMap.class).aggregateFunction(new FreqMapAggregator()).serialiser(new FreqMapSerialiser()).build()).build();
converter = createConverter(schema);
final Entity entity = new Entity.Builder().vertex("vertex1").property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
// When 1
final Value value = converter.getValueFromProperties(TestGroups.ENTITY, entity.getProperties());
// Then 1
assertTrue(value.getSize() > 0);
// When 2
final Properties properties = converter.getPropertiesFromValue(TestGroups.ENTITY, value);
// Then 2
assertEquals(entity.getProperties(), properties);
}
use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldDeserialiseEntityId.
@Test
public void shouldDeserialiseEntityId() {
// Given
final EntityId expectedElementId = new EntitySeed("vertex1");
final Entity entity = new Entity.Builder().vertex("vertex1").group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
final Key key = converter.getKeyFromEntity(entity);
// When
final ElementId elementId = converter.getElementId(key, false);
// Then
assertEquals(expectedElementId, elementId);
}
use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.
the class FullSchemaLoader method createEdges.
@Override
public Map<EdgeId, Edge> createEdges() {
final Map<EdgeId, Edge> edges = new HashMap<>();
for (int i = 0; i <= 10; i++) {
for (int j = 0; j < VERTEX_PREFIXES.length; j++) {
final FreqMap freqMap = new FreqMap();
freqMap.upsert("key");
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source(VERTEX_PREFIXES[0] + i).dest(VERTEX_PREFIXES[j] + i).directed(false).property(TestPropertyNames.COUNT, 1L).property(TestPropertyNames.PROP_1, 1).property(TestPropertyNames.PROP_2, 1L).property(TestPropertyNames.PROP_3, "1").property(TestPropertyNames.PROP_4, freqMap).property(TestPropertyNames.PROP_5, "property").property(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1))).property(TestPropertyNames.TIMESTAMP, 1L).property(TestPropertyNames.VISIBILITY, "public").build();
addToMap(edge, edges);
final FreqMap freqMap2 = new FreqMap();
freqMap2.upsert("key");
final Edge edgeDir = new Edge.Builder().group(TestGroups.EDGE).source(VERTEX_PREFIXES[0] + i).dest(VERTEX_PREFIXES[j] + i).directed(true).property(TestPropertyNames.COUNT, 1L).property(TestPropertyNames.PROP_1, 1).property(TestPropertyNames.PROP_2, 1L).property(TestPropertyNames.PROP_3, "1").property(TestPropertyNames.PROP_4, freqMap2).property(TestPropertyNames.PROP_5, "property").property(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1))).property(TestPropertyNames.TIMESTAMP, 1L).property(TestPropertyNames.VISIBILITY, "private").build();
addToMap(edgeDir, edges);
}
final FreqMap freqMap3 = new FreqMap();
freqMap3.upsert("key");
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source(SOURCE + i).dest(DEST + i).directed(false).property(TestPropertyNames.COUNT, 1L).property(TestPropertyNames.PROP_1, 1).property(TestPropertyNames.PROP_2, 1L).property(TestPropertyNames.PROP_3, "1").property(TestPropertyNames.PROP_4, freqMap3).property(TestPropertyNames.PROP_5, "property").property(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1))).property(TestPropertyNames.TIMESTAMP, 1L).property(TestPropertyNames.VISIBILITY, "public").build();
addToMap(edge, edges);
final FreqMap freqMap4 = new FreqMap();
freqMap4.upsert("key");
final Edge edgeDir = new Edge.Builder().group(TestGroups.EDGE).source(SOURCE_DIR + i).dest(DEST_DIR + i).directed(true).property(TestPropertyNames.COUNT, 1L).property(TestPropertyNames.PROP_1, 1).property(TestPropertyNames.PROP_2, 1L).property(TestPropertyNames.PROP_3, "1").property(TestPropertyNames.PROP_4, freqMap4).property(TestPropertyNames.PROP_5, "property").property(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1))).property(TestPropertyNames.TIMESTAMP, 1L).property(TestPropertyNames.VISIBILITY, "private").build();
addToMap(edgeDir, edges);
}
return edges;
}
use of uk.gov.gchq.gaffer.types.FreqMap in project Gaffer by gchq.
the class ElementSerialisationTest method shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty.
@Test
public void shouldSerialiseAndDeserialisePropertiesWhenAllAreEmpty() throws Exception {
// Given
final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("string").property(HBasePropertyNames.PROP_1, "map").property(HBasePropertyNames.PROP_2, "map").build()).type("string", String.class).type("map", new TypeDefinition.Builder().clazz(FreqMap.class).aggregateFunction(new FreqMapAggregator()).serialiser(new FreqMapSerialiser()).build()).build();
serialisation = new ElementSerialisation(schema);
final Entity entity = new Entity.Builder().vertex("vertex1").property(HBasePropertyNames.PROP_1, new FreqMap()).property(HBasePropertyNames.PROP_2, new FreqMap()).build();
// When 1
final byte[] value = serialisation.getValue(TestGroups.ENTITY, entity.getProperties());
// Then 1
assertArrayEquals(new byte[] { ByteArrayEscapeUtils.DELIMITER, ByteArrayEscapeUtils.DELIMITER }, value);
// When 2
final Properties properties = serialisation.getPropertiesFromValue(TestGroups.ENTITY, value);
// Then 2
assertEquals(entity.getProperties(), properties);
}
Aggregations