Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeleteElements to return count #3356

Merged
merged 10 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 33 additions & 45 deletions core/graph/src/test/java/uk/gov/gchq/gaffer/graph/GraphTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 Crown Copyright
* Copyright 2016-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -342,7 +342,7 @@ public void shouldCreateNewContextInstanceWhenExecuteOperation(@Mock final Store

@Test
public void shouldCreateNewContextInstanceWhenExecuteOutputOperation(@Mock final Store store)
throws OperationException, IOException {
throws OperationException {
// Given
final Schema schema = new Schema();
given(store.getProperties()).willReturn(new StoreProperties());
Expand All @@ -365,7 +365,7 @@ public void shouldCreateNewContextInstanceWhenExecuteOutputOperation(@Mock final

@Test
public void shouldCreateNewContextInstanceWhenExecuteJob(@Mock final Store store)
throws OperationException, IOException {
throws OperationException {
// Given
final Schema schema = new Schema();
given(store.getProperties()).willReturn(new StoreProperties());
Expand Down Expand Up @@ -1065,7 +1065,7 @@ public void shouldNotSetGraphViewOnOperationWhenOperationIsNotAGet(@Mock final S
}

@Test
public void shouldThrowExceptionIfStoreClassPropertyIsNotSet() throws OperationException {
public void shouldThrowExceptionIfStoreClassPropertyIsNotSet() {
try {
new Graph.Builder()
.config(new GraphConfig.Builder()
Expand Down Expand Up @@ -1097,15 +1097,10 @@ public void shouldThrowExceptionIfGraphIdIsMissing() {
}

@Test
public void shouldThrowExceptionIfSchemaIsInvalid() throws OperationException {
public void shouldThrowExceptionIfSchemaIsInvalid() {
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
try {
new Graph.Builder()
.config(new GraphConfig.Builder()
.graphId(GRAPH_ID)
.build())
.addSchema(new Schema.Builder()
final Schema invalidSchema = new Schema.Builder()
.type("int", new TypeDefinition.Builder()
.clazz(Integer.class)
.aggregateFunction(new Sum())
Expand All @@ -1126,13 +1121,17 @@ public void shouldThrowExceptionIfSchemaIsInvalid() throws OperationException {
.vertex("string")
.property("p2", "int")
.build())
.build())
.build();
final GraphConfig config = new GraphConfig.Builder()
.graphId(GRAPH_ID)
.build();
assertThatExceptionOfType(SchemaException.class)
.isThrownBy(() -> new Graph.Builder()
.config(config)
.addSchema(invalidSchema)
.storeProperties(storeProperties)
.build();
fail("exception expected");
} catch (final SchemaException e) {
assertNotNull(e.getMessage());
}
.build())
.withMessageContaining("Schema is not valid");
}

@Test
Expand Down Expand Up @@ -1254,7 +1253,7 @@ private void writeToFile(final String schemaFile, final File dir) throws IOExcep
}

@Test
public void shouldThrowExceptionIfGraphIdIsInvalid(@Mock final StoreProperties properties) throws Exception {
void shouldThrowExceptionIfGraphIdIsInvalid(@Mock final StoreProperties properties) {
try {
new Graph.Builder()
.config(new GraphConfig.Builder()
Expand Down Expand Up @@ -1355,8 +1354,7 @@ public void shouldBuildGraphUsingGraphIdAndLookupSchema() throws Exception {

@Test
public void shouldAddHooksVarArgsAndGetGraphHooks(@Mock final GraphHook graphHook1,
@Mock final Log4jLogger graphHook2)
throws Exception {
@Mock final Log4jLogger graphHook2) {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
Expand All @@ -1382,8 +1380,7 @@ public void shouldAddHooksVarArgsAndGetGraphHooks(@Mock final GraphHook graphHoo

@Test
public void shouldAddHookAndGetGraphHooks(@Mock final GraphHook graphHook1,
@Mock final Log4jLogger graphHook3)
throws Exception {
@Mock final Log4jLogger graphHook3) {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStore.class.getName());
Expand Down Expand Up @@ -1417,8 +1414,7 @@ public void shouldAddHookAndGetGraphHooks(@Mock final GraphHook graphHook1,

@Test
public void shouldAddNamedViewResolverHookAfterNamedOperationResolver(@Mock final GraphHook graphHook1,
@Mock final Log4jLogger graphHook2)
throws Exception {
@Mock final Log4jLogger graphHook2) {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStore.class.getName());
Expand Down Expand Up @@ -1511,7 +1507,7 @@ public void shouldAddHookFromPathAndGetGraphHooks() throws Exception {
}

@Test
public void shouldBuildGraphFromConfigFile() throws Exception {
void shouldBuildGraphFromConfigFile() {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
Expand Down Expand Up @@ -1541,8 +1537,7 @@ public void shouldBuildGraphFromConfigFile() throws Exception {

@Test
public void shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig(@Mock final GraphLibrary library1, @Mock final GraphLibrary library2,
@Mock final GraphHook hook1, @Mock final GraphHook hook2, @Mock final GraphHook hook3)
throws Exception {
@Mock final GraphHook hook1, @Mock final GraphHook hook2, @Mock final GraphHook hook3) {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
Expand Down Expand Up @@ -1591,8 +1586,7 @@ public void shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig(@Mock fin

@Test
public void shouldBuildGraphFromConfigAndOverrideFields(@Mock final GraphLibrary library1, @Mock final GraphLibrary library2,
@Mock final GraphHook hook1, @Mock final GraphHook hook2, @Mock final GraphHook hook3)
throws Exception {
@Mock final GraphHook hook1, @Mock final GraphHook hook2, @Mock final GraphHook hook3) {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
Expand Down Expand Up @@ -1642,7 +1636,7 @@ public void shouldBuildGraphFromConfigAndOverrideFields(@Mock final GraphLibrary
}

@Test
public void shouldReturnClonedViewFromConfig() throws Exception {
void shouldReturnClonedViewFromConfig() {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
Expand Down Expand Up @@ -1840,8 +1834,7 @@ public void shouldCorrectlySetViewForNestedOperationChain() throws OperationExce
}

@Test
public void shouldThrowExceptionOnExecuteWithANullContext(@Mock final OperationChain opChain)
throws OperationException {
void shouldThrowExceptionOnExecuteWithANullContext(@Mock final OperationChain opChain) {
// Given
final Context context = null;

Expand All @@ -1860,8 +1853,7 @@ public void shouldThrowExceptionOnExecuteWithANullContext(@Mock final OperationC
}

@Test
public void shouldThrowExceptionOnExecuteJobWithANullContext(@Mock final OperationChain opChain)
throws OperationException {
void shouldThrowExceptionOnExecuteJobWithANullContext(@Mock final OperationChain opChain) {
// Given
final Context context = null;

Expand All @@ -1880,8 +1872,7 @@ public void shouldThrowExceptionOnExecuteJobWithANullContext(@Mock final Operati
}

@Test
public void shouldThrowExceptionOnExecuteWithANullUser(@Mock final OperationChain opChain)
throws OperationException {
void shouldThrowExceptionOnExecuteWithANullUser(@Mock final OperationChain opChain) {
// Given
final User user = null;

Expand All @@ -1900,8 +1891,7 @@ public void shouldThrowExceptionOnExecuteWithANullUser(@Mock final OperationChai
}

@Test
public void shouldThrowExceptionOnExecuteJobWithANullUser(@Mock final OperationChain opChain)
throws OperationException {
void shouldThrowExceptionOnExecuteJobWithANullUser(@Mock final OperationChain opChain) {
// Given
final User user = null;

Expand All @@ -1920,8 +1910,7 @@ public void shouldThrowExceptionOnExecuteJobWithANullUser(@Mock final OperationC
}

@Test
public void shouldThrowExceptionOnExecuteJobUsingJobWithANullContext(@Mock final OperationChain opChain)
throws OperationException {
void shouldThrowExceptionOnExecuteJobUsingJobWithANullContext(@Mock final OperationChain opChain) {
// Given
final Context context = null;

Expand All @@ -1942,7 +1931,7 @@ public void shouldThrowExceptionOnExecuteJobUsingJobWithANullContext(@Mock final
}

@Test
public void shouldThrowExceptionOnExecuteJobUsingJobWithANullOperation() throws OperationException {
void shouldThrowExceptionOnExecuteJobUsingJobWithANullOperation() {
// Given
final Context context = new Context();

Expand All @@ -1963,7 +1952,7 @@ public void shouldThrowExceptionOnExecuteJobUsingJobWithANullOperation() throws
}

@Test
public void shouldThrowExceptionOnExecuteJobUsingJobWithANullJob() throws OperationException {
void shouldThrowExceptionOnExecuteJobUsingJobWithANullJob() {
// Given
final Context context = new Context();

Expand All @@ -1984,8 +1973,7 @@ public void shouldThrowExceptionOnExecuteJobUsingJobWithANullJob() throws Operat
}

@Test
public void shouldThrowExceptionOnExecuteJobUsingJobWithANullUser(@Mock final OperationChain opChain)
throws OperationException {
void shouldThrowExceptionOnExecuteJobUsingJobWithANullUser(@Mock final OperationChain opChain) {
// Given
final User user = null;

Expand Down Expand Up @@ -2744,7 +2732,7 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
}

@Override
protected OperationHandler<? extends DeleteElements> getDeleteElementsHandler() {
protected OutputOperationHandler<DeleteElements, Long> getDeleteElementsHandler() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 Crown Copyright
* Copyright 2016-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -86,7 +86,7 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
}

@Override
protected OperationHandler<? extends DeleteElements> getDeleteElementsHandler() {
protected OutputOperationHandler<DeleteElements, Long> getDeleteElementsHandler() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Crown Copyright
* Copyright 2024-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,14 +18,18 @@

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.type.TypeReference;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import uk.gov.gchq.gaffer.commonutil.ToStringBuilder;
import uk.gov.gchq.gaffer.data.element.Element;
import uk.gov.gchq.gaffer.operation.Operation;
import uk.gov.gchq.gaffer.operation.Validatable;
import uk.gov.gchq.gaffer.operation.io.InputOutput;
import uk.gov.gchq.gaffer.operation.io.MultiInput;
import uk.gov.gchq.gaffer.operation.serialisation.TypeReferenceImpl;
import uk.gov.gchq.koryphe.Since;
import uk.gov.gchq.koryphe.Summary;

Expand All @@ -50,7 +54,8 @@
@Summary("Deletes elements")
public class DeleteElements implements
Validatable,
MultiInput<Element> {
MultiInput<Element>,
InputOutput<Iterable<? extends Element>, Long> {
private boolean validate = true;
private boolean skipInvalidElements;
private Iterable<? extends Element> elements;
Expand Down Expand Up @@ -92,6 +97,11 @@
this.elements = elements;
}

@Override
public TypeReference<Long> getOutputTypeReference() {
return new TypeReferenceImpl.Long();

Check warning on line 102 in core/operation/src/main/java/uk/gov/gchq/gaffer/operation/impl/delete/DeleteElements.java

View check run for this annotation

Codecov / codecov/patch

core/operation/src/main/java/uk/gov/gchq/gaffer/operation/impl/delete/DeleteElements.java#L102

Added line #L102 was not covered by tests
}

@Override
public Map<String, String> getOptions() {
return options;
Expand Down Expand Up @@ -154,7 +164,7 @@

public static class Builder extends Operation.BaseBuilder<DeleteElements, Builder>
implements Validatable.Builder<DeleteElements, Builder>,
MultiInput.Builder<DeleteElements, Element, Builder> {
MultiInput.Builder<DeleteElements, Element, Builder>, InputOutput.Builder<DeleteElements, Iterable<? extends Element>, Long, Builder> {
public Builder() {
super(new DeleteElements());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ public List<OperationChainOptimiser> getOperationChainOptimisers() {
*
* @return the implementation of the handler for {@link uk.gov.gchq.gaffer.operation.impl.delete.DeleteElements}
*/
protected abstract OperationHandler<? extends DeleteElements> getDeleteElementsHandler();
protected abstract OutputOperationHandler<DeleteElements, Long> getDeleteElementsHandler();

/**
* Get this Store's implementation of the handler for {@link uk.gov.gchq.gaffer.operation.DeleteAllData}.
Expand Down
13 changes: 6 additions & 7 deletions core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import uk.gov.gchq.gaffer.data.element.LazyEntity;
import uk.gov.gchq.gaffer.data.element.id.EntityId;
import uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException;
import uk.gov.gchq.gaffer.exception.SerialisationException;
import uk.gov.gchq.gaffer.jobtracker.Job;
import uk.gov.gchq.gaffer.jobtracker.JobDetail;
import uk.gov.gchq.gaffer.jobtracker.JobStatus;
Expand Down Expand Up @@ -420,7 +419,7 @@ public void shouldCloseOperationIfExceptionThrown(@Mock final StoreProperties pr
}

@Test
public void shouldThrowExceptionIfOperationChainIsInvalid(@Mock final StoreProperties properties) throws OperationException, StoreException {
public void shouldThrowExceptionIfOperationChainIsInvalid(@Mock final StoreProperties properties) throws StoreException {
// Given
final Schema schema = createSchemaMock();
final OperationChain<?> opChain = new OperationChain<>();
Expand All @@ -440,7 +439,7 @@ public void shouldThrowExceptionIfOperationChainIsInvalid(@Mock final StorePrope
}

@Test
public void shouldCallDoUnhandledOperationWhenDoOperationWithUnknownOperationClass(@Mock final StoreProperties properties) throws Exception {
void shouldCallDoUnhandledOperationWhenDoOperationWithUnknownOperationClass(@Mock final StoreProperties properties) throws Exception {
// Given
final Schema schema = createSchemaMock();
final Operation operation = new SetVariable.Builder().variableName("aVariable").input("inputString").build();
Expand Down Expand Up @@ -806,7 +805,7 @@ public void shouldExecuteOperationChainJob(@Mock final StoreProperties propertie

@Test
public void shouldExecuteOperationJobAndWrapJobOperationInChain(@Mock final StoreProperties properties)
throws OperationException, InterruptedException, StoreException, SerialisationException {
throws OperationException, InterruptedException, StoreException {
// Given
final Operation operation = new GetVariables.Builder().variableNames(Lists.newArrayList()).build();
given(properties.getJobExecutorThreadCount()).willReturn(1);
Expand Down Expand Up @@ -1185,7 +1184,7 @@ protected OperationHandler<AddElements> getAddElementsHandler() {


@Override
protected OperationHandler<? extends DeleteElements> getDeleteElementsHandler() {
protected OutputOperationHandler<DeleteElements, Long> getDeleteElementsHandler() {
return null;
}

Expand Down Expand Up @@ -1286,7 +1285,7 @@ protected OperationHandler<AddElements> getAddElementsHandler() {


@Override
protected OperationHandler<? extends DeleteElements> getDeleteElementsHandler() {
protected OutputOperationHandler<DeleteElements, Long> getDeleteElementsHandler() {
return null;
}

Expand Down Expand Up @@ -1396,7 +1395,7 @@ protected OperationHandler<AddElements> getAddElementsHandler() {
}

@Override
protected OperationHandler<? extends DeleteElements> getDeleteElementsHandler() {
protected OutputOperationHandler<DeleteElements, Long> getDeleteElementsHandler() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 Crown Copyright
* Copyright 2016-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -145,7 +145,7 @@ protected OperationHandler<? extends AddElements> getAddElementsHandler() {
}

@Override
protected OperationHandler<? extends DeleteElements> getDeleteElementsHandler() {
protected OutputOperationHandler<DeleteElements, Long> getDeleteElementsHandler() {
return null;
}

Expand Down
Loading
Loading