Search in sources :

Example 91 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class DefaultScoreResolverTest method shouldGetScoreForOperationChain.

@Test
public void shouldGetScoreForOperationChain() {
    // Given
    final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
    final GetElements getElements = mock(GetElements.class);
    final Limit limit = mock(Limit.class);
    final List<Operation> opList = Arrays.asList(getAdjacentIds, getElements, limit);
    final OperationChain opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(opList);
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(GetElements.class, 2);
    opScores.put(GetAdjacentIds.class, 3);
    opScores.put(Limit.class, 1);
    final DefaultScoreResolver resolver = new DefaultScoreResolver(opScores);
    // When
    final int score = resolver.getScore(opChain);
    // Then
    assertEquals(6, score);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 92 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class DefaultScoreResolverTest method shouldGetScoreForOperationChainContainingNamedOperation.

@Test
public void shouldGetScoreForOperationChainContainingNamedOperation() throws OperationException {
    // Given
    final ScoreResolver mockResolver = mock(NamedOperationScoreResolver.class);
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(GetAdjacentIds.class, 2);
    opScores.put(GetElements.class, 3);
    opScores.put(Limit.class, 4);
    final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
    final String opName = "basicOp";
    final NamedOperation<Object, Object> namedOp = new Builder<>().name(opName).build();
    resolvers.put(NamedOperation.class, mockResolver);
    given(mockResolver.getScore(eq(namedOp), any())).willReturn(5);
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetElements()).then(new Limit()).then(new GetWalks.Builder().addOperations(namedOp, new GetElements()).build()).build();
    final DefaultScoreResolver scoreResolver = new DefaultScoreResolver(opScores, resolvers);
    // When
    final Object result = scoreResolver.getScore(opChain);
    // Then
    assertEquals(17, result);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Builder(uk.gov.gchq.gaffer.named.operation.NamedOperation.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 93 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class DefaultScoreResolverTest method shouldPreventInfiniteRecusion.

@Test
public void shouldPreventInfiniteRecusion() throws OperationException {
    // Given
    final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
    resolvers.put(GetElements.class, new ScoreResolver() {

        @Override
        public Integer getScore(final Operation operation) {
            throw new IllegalArgumentException("defaultResolver is required");
        }

        @Override
        public Integer getScore(final Operation operation, final ScoreResolver defaultScoreResolver) {
            // infinite loop
            return defaultScoreResolver.getScore(operation);
        }
    });
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetElements()).build();
    final DefaultScoreResolver scoreResolver = new DefaultScoreResolver(null, resolvers);
    // When
    final Object result = scoreResolver.getScore(opChain);
    // Then
    assertEquals(2, result);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.jupiter.api.Test)

Example 94 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class DefaultScoreResolverTest method shouldGetScoreForOperationChainWhenNamedOperationScoreIsNull.

@Test
public void shouldGetScoreForOperationChainWhenNamedOperationScoreIsNull() throws OperationException {
    // Given
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(GetAdjacentIds.class, 2);
    opScores.put(GetElements.class, 1);
    opScores.put(Limit.class, 1);
    final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
    final String opName = "basicOp";
    final NamedOperation<Object, Object> namedOp = new Builder<>().name(opName).build();
    final ScoreResolver mockResolver = mock(NamedOperationScoreResolver.class);
    resolvers.put(NamedOperation.class, mockResolver);
    given(mockResolver.getScore(eq(namedOp), any())).willReturn(null);
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetElements()).then(new Limit()).then(namedOp).build();
    final DefaultScoreResolver scoreResolver = new DefaultScoreResolver(opScores, resolvers);
    // When
    final Object result = scoreResolver.getScore(opChain);
    // Then
    assertEquals(5, result);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Builder(uk.gov.gchq.gaffer.named.operation.NamedOperation.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 95 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class DefaultScoreResolverTest method shouldGetScore.

@Test
public void shouldGetScore() {
    // Given
    final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(GetAdjacentIds.class, 2);
    opScores.put(GetElements.class, 1);
    opScores.put(Limit.class, 1);
    final DefaultScoreResolver resolver = new DefaultScoreResolver(opScores);
    // When
    final int score = resolver.getScore(op1);
    // Then
    assertEquals(2, score);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)136 Test (org.junit.jupiter.api.Test)88 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)49 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)44 Schema (uk.gov.gchq.gaffer.store.schema.Schema)41 Context (uk.gov.gchq.gaffer.store.Context)35 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)34 Store (uk.gov.gchq.gaffer.store.Store)28 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)26 LinkedHashMap (java.util.LinkedHashMap)21 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)21 User (uk.gov.gchq.gaffer.user.User)21 ArrayList (java.util.ArrayList)18 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)18 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)17 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)16 HashSet (java.util.HashSet)15 HashMap (java.util.HashMap)13 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)13 OperationException (uk.gov.gchq.gaffer.operation.OperationException)13