Skip to content

Commit

Permalink
gh-2823 FederatedStore unsupported operations are forwarded to subgra…
Browse files Browse the repository at this point in the history
…phs. Tests
  • Loading branch information
GCHQDev404 committed Nov 15, 2022
1 parent 3bc83fd commit adae6ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ protected Object doUnhandledOperation(final Operation operation, final Context c
.doOperation(operation, context, this);
}
} catch (final Exception e) {
throw new GafferRuntimeException(String.format("Error with FederatedStore forwarding unhandled operation to sub-graphs due to: %s", e.getMessage()), e);
throw new UnsupportedOperationException(String.format("Operation class %s is not supported by the FederatedStore. Error occurred forwarding unhandled operation to sub-graphs due to: %s", operation.getClass().getName(), e.getMessage()), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package uk.gov.gchq.gaffer.federatedstore;

import com.google.common.collect.Sets;
import org.apache.commons.lang3.exception.CloneFailedException;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -33,6 +34,7 @@
import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.commonutil.JsonAssert;
import uk.gov.gchq.gaffer.commonutil.StreamUtil;
import uk.gov.gchq.gaffer.core.exception.GafferRuntimeException;
import uk.gov.gchq.gaffer.data.element.Edge;
import uk.gov.gchq.gaffer.data.element.Element;
import uk.gov.gchq.gaffer.data.element.Entity;
Expand Down Expand Up @@ -69,6 +71,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -270,13 +273,28 @@ public void shouldNotAllowOverwritingOfGraphWithinFederatedScope() throws Except
@Test
public void shouldThrowAppropriateExceptionWhenHandlingAnUnsupportedOperation() {
// Given
final Operation op = new OperationImpl();
final Operation unknownOperation = new Operation() {
@Override
public Operation shallowClone() throws CloneFailedException {
return this;
}

@Override
public Map<String, String> getOptions() {
return null;
}

@Override
public void setOptions(final Map<String, String> options) {

}
};
// When
// Expected an UnsupportedOperationException rather than an OperationException

// Then
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> store.handleOperation(op, new Context()))
.withMessage("Operation class uk.gov.gchq.gaffer.operation.impl.OperationImpl is not supported by the FederatedStore.");
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> store.handleOperation(unknownOperation, new Context()))
.withMessageContaining("Operation class uk.gov.gchq.gaffer.federatedstore.FederatedStoreTest$1 is not supported by the FederatedStore.");
}

@Test
Expand Down

0 comments on commit adae6ba

Please sign in to comment.