Search in sources :

Example 1 with EdgeDirection

use of uk.gov.gchq.gaffer.data.element.EdgeDirection in project Gaffer by gchq.

the class ElementSerialisationTest method shouldDeserialiseSourceDestinationValuesUndirected.

@Test
public void shouldDeserialiseSourceDestinationValuesUndirected() throws SerialisationException {
    final Edge edge = new Edge.Builder().source("1").dest("2").directed(false).group(TestGroups.ENTITY).build();
    final byte[] rowKey = serialisation.getRowKeys(edge).getFirst();
    final byte[][] sourceDestValues = new byte[2][];
    // When
    final EdgeDirection direction = serialisation.getSourceAndDestination(rowKey, sourceDestValues);
    // Then
    assertEquals(EdgeDirection.UNDIRECTED, direction);
}
Also used : EdgeDirection(uk.gov.gchq.gaffer.data.element.EdgeDirection) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 2 with EdgeDirection

use of uk.gov.gchq.gaffer.data.element.EdgeDirection in project Gaffer by gchq.

the class ElementSerialisationTest method shouldDeserialiseSourceDestinationValuesCorrectWayRound.

@Test
public void shouldDeserialiseSourceDestinationValuesCorrectWayRound() throws SerialisationException {
    // Given
    final Edge edge = new Edge.Builder().source("1").dest("2").directed(true).group(TestGroups.ENTITY).build();
    final byte[] rowKey = serialisation.getRowKeys(edge).getFirst();
    final byte[][] sourceDestValues = new byte[2][];
    // When
    final EdgeDirection direction = serialisation.getSourceAndDestination(rowKey, sourceDestValues);
    // Then
    assertEquals(EdgeDirection.DIRECTED, direction);
}
Also used : EdgeDirection(uk.gov.gchq.gaffer.data.element.EdgeDirection) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 3 with EdgeDirection

use of uk.gov.gchq.gaffer.data.element.EdgeDirection in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverterTest method shouldDeserialiseSourceDestinationValuesUndirected.

@Test
public void shouldDeserialiseSourceDestinationValuesUndirected() {
    // Given
    final Edge edge = new Edge.Builder().source("1").dest("2").directed(false).group(TestGroups.ENTITY).build();
    final byte[] rowKey = converter.getRowKeysFromEdge(edge).getSecond();
    final byte[][] sourceDestValues = new byte[2][];
    // When
    final EdgeDirection direction = converter.getSourceAndDestinationFromRowKey(rowKey, sourceDestValues);
    // Then
    assertEquals(EdgeDirection.UNDIRECTED, direction);
}
Also used : EdgeDirection(uk.gov.gchq.gaffer.data.element.EdgeDirection) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test) AbstractAccumuloElementConverterTest(uk.gov.gchq.gaffer.accumulostore.key.AbstractAccumuloElementConverterTest)

Example 4 with EdgeDirection

use of uk.gov.gchq.gaffer.data.element.EdgeDirection in project Gaffer by gchq.

the class ClassicAccumuloElementConverter method getSourceAndDestinationFromRowKey.

@Override
protected EdgeDirection getSourceAndDestinationFromRowKey(final byte[] rowKey, final byte[][] sourceDestValue) {
    // Get sourceValue, destinationValue and directed flag from row key
    // Expect to find 2 delimiters (3 fields)
    final int[] positionsOfDelimiters = new int[2];
    short numDelims = 0;
    for (int i = 0; i < rowKey.length; i++) {
        if (rowKey[i] == ByteArrayEscapeUtils.DELIMITER) {
            if (numDelims >= 2) {
                throw new AccumuloElementConversionException("Too many delimiters found in row key - found more than the expected 2.");
            }
            positionsOfDelimiters[numDelims++] = i;
        }
    }
    if (numDelims != 2) {
        throw new AccumuloElementConversionException("Wrong number of delimiters found in row key - found " + numDelims + ", expected 2.");
    }
    // If edge is undirected then create edge
    // (no need to worry about which direction the vertices should go in).
    // If the edge is directed then need to decide which way round the vertices should go.
    final int directionFlag = rowKey[rowKey.length - 1];
    byte[] sourceBytes = ByteArrayEscapeUtils.unEscape(rowKey, 0, positionsOfDelimiters[0]);
    byte[] destBytes = ByteArrayEscapeUtils.unEscape(rowKey, positionsOfDelimiters[0] + 1, positionsOfDelimiters[1]);
    sourceDestValue[0] = sourceBytes;
    sourceDestValue[1] = destBytes;
    EdgeDirection rtn;
    switch(directionFlag) {
        case ClassicBytePositions.UNDIRECTED_EDGE:
            // Edge is undirected
            rtn = EdgeDirection.UNDIRECTED;
            break;
        case ClassicBytePositions.CORRECT_WAY_DIRECTED_EDGE:
            // Edge is directed and the first identifier is the source of the edge
            rtn = EdgeDirection.DIRECTED;
            break;
        case ClassicBytePositions.INCORRECT_WAY_DIRECTED_EDGE:
            // Edge is directed and the second identifier is the source of the edge
            sourceDestValue[0] = destBytes;
            sourceDestValue[1] = sourceBytes;
            rtn = EdgeDirection.DIRECTED_REVERSED;
            break;
        default:
            throw new AccumuloElementConversionException("Invalid direction flag in row key - flag was " + directionFlag);
    }
    return rtn;
}
Also used : EdgeDirection(uk.gov.gchq.gaffer.data.element.EdgeDirection) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 5 with EdgeDirection

use of uk.gov.gchq.gaffer.data.element.EdgeDirection in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverterTest method shouldDeserialiseSourceDestinationValuesCorrectWayRound.

@Test
public void shouldDeserialiseSourceDestinationValuesCorrectWayRound() {
    // Given
    final Edge edge = new Edge.Builder().source("1").dest("2").directed(true).group(TestGroups.ENTITY).build();
    final byte[] rowKey = converter.getRowKeysFromEdge(edge).getFirst();
    final byte[][] sourceDestValues = new byte[2][];
    // When
    final EdgeDirection direction = converter.getSourceAndDestinationFromRowKey(rowKey, sourceDestValues);
    // Then
    assertEquals(EdgeDirection.DIRECTED, direction);
}
Also used : EdgeDirection(uk.gov.gchq.gaffer.data.element.EdgeDirection) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test) AbstractAccumuloElementConverterTest(uk.gov.gchq.gaffer.accumulostore.key.AbstractAccumuloElementConverterTest)

Aggregations

EdgeDirection (uk.gov.gchq.gaffer.data.element.EdgeDirection)12 Edge (uk.gov.gchq.gaffer.data.element.Edge)8 Test (org.junit.jupiter.api.Test)6 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)4 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 AbstractAccumuloElementConverterTest (uk.gov.gchq.gaffer.accumulostore.key.AbstractAccumuloElementConverterTest)3 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)3 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)1