Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into gh-2435-FederatedS…
Browse files Browse the repository at this point in the history
…tore-changeGraphId-table-name-fix
  • Loading branch information
GCHQDev404 committed Aug 11, 2021
2 parents cdb4cbd + 5170aff commit 0531595
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 38 deletions.
@@ -0,0 +1,60 @@
/*
* Copyright 2021 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.gchq.gaffer.federatedstore.integration;

import org.junit.jupiter.api.BeforeEach;

import uk.gov.gchq.gaffer.commonutil.StreamUtil;
import uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties;
import uk.gov.gchq.gaffer.graph.Graph;
import uk.gov.gchq.gaffer.integration.AbstractStoreIT;
import uk.gov.gchq.gaffer.store.schema.Schema;
import uk.gov.gchq.gaffer.user.User;

public abstract class AbstractStandaloneFederatedStoreIT {

protected Graph graph;
protected User user = new User();

@BeforeEach
public void setUp() throws Exception {
createGraph();
_setUp();
}

protected void _setUp() throws Exception {
// Override if required;
}

private void createGraph() {
graph = new Graph.Builder()
.config(AbstractStoreIT.createDefaultGraphConfig())
.storeProperties(getStoreProperties())
.addSchema(createSchema())
.build();
}

private FederatedStoreProperties getStoreProperties() {
return FederatedStoreProperties.loadStoreProperties(
StreamUtil.openStream(FederatedStoreITs.class, "publicAccessPredefinedFederatedStore.properties"));

}

protected Schema createSchema() {
return AbstractStoreIT.createDefaultSchema();
}
}
Expand Up @@ -18,8 +18,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.accumulo.core.client.Connector;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties;
import uk.gov.gchq.gaffer.accumulostore.utils.TableUtils;
Expand Down Expand Up @@ -55,7 +54,7 @@
import static org.junit.Assert.assertTrue;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS;

public class FederatedAdminIT extends AbstractStoreIT {
public class FederatedAdminIT extends AbstractStandaloneFederatedStoreIT {

public static final User ADMIN_USER = new User("admin", Collections.EMPTY_SET, Sets.newHashSet("AdminAuth"));
public static final User NOT_ADMIN_USER = new User("admin", Collections.EMPTY_SET, Sets.newHashSet("NotAdminAuth"));
Expand All @@ -67,14 +66,14 @@ public class FederatedAdminIT extends AbstractStoreIT {

@Override
protected Schema createSchema() {
final Schema.Builder schemaBuilder = new Schema.Builder(createDefaultSchema());
final Schema.Builder schemaBuilder = new Schema.Builder(AbstractStoreIT.createDefaultSchema());
schemaBuilder.edges(Collections.EMPTY_MAP);
schemaBuilder.entities(Collections.EMPTY_MAP);
return schemaBuilder.build();
}

@Before
public void setUp() throws Exception {
@Override
public void _setUp() throws Exception {
graph.execute(new RemoveGraph.Builder()
.graphId(PublicAccessPredefinedFederatedStore.ACCUMULO_GRAPH_WITH_EDGES)
.build(), user);
Expand Down
Expand Up @@ -31,9 +31,5 @@ public FederatedStoreITs() {
protected FederatedStoreITs(final FederatedStoreProperties storeProperties) {
super(storeProperties);
skipTestMethod(GetWalksIT.class, "shouldReturnNoResultsWhenNoEntityResults", "Fails due to the way we split the entities and edges into 2 graphs");
addExtraTest(FederatedViewsIT.class);
addExtraTest(FederatedAdminIT.class);
addExtraTest(FederatedStoreRecursionIT.class);

}
}
Expand Up @@ -17,24 +17,22 @@

import com.google.common.collect.Lists;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import uk.gov.gchq.gaffer.cache.CacheServiceLoader;
import uk.gov.gchq.gaffer.data.element.Element;
import uk.gov.gchq.gaffer.data.element.Entity;
import uk.gov.gchq.gaffer.federatedstore.FederatedStore;
import uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties;
import uk.gov.gchq.gaffer.federatedstore.PublicAccessPredefinedFederatedStore;
import uk.gov.gchq.gaffer.federatedstore.SingleUseFederatedStore;
import uk.gov.gchq.gaffer.federatedstore.operation.AddGraph;
import uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain;
import uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds;
import uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph;
import uk.gov.gchq.gaffer.graph.Graph;
import uk.gov.gchq.gaffer.graph.GraphConfig;
import uk.gov.gchq.gaffer.integration.AbstractStoreIT;
import uk.gov.gchq.gaffer.mapstore.MapStoreProperties;
import uk.gov.gchq.gaffer.operation.OperationChain;
import uk.gov.gchq.gaffer.operation.OperationException;
Expand All @@ -44,6 +42,7 @@
import uk.gov.gchq.gaffer.store.schema.Schema;
import uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition;
import uk.gov.gchq.gaffer.store.schema.TypeDefinition;
import uk.gov.gchq.gaffer.user.User;
import uk.gov.gchq.koryphe.impl.binaryoperator.Sum;
import uk.gov.gchq.koryphe.impl.predicate.Exists;
import uk.gov.gchq.koryphe.impl.predicate.IsEqual;
Expand All @@ -53,7 +52,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class FederatedStoreRecursionIT extends AbstractStoreIT {
public class FederatedStoreRecursionIT {
private static final Logger LOGGER = LoggerFactory.getLogger(FederatedStore.class);
public static final String INNER_FEDERATED_GRAPH = "innerFederatedGraph";
public static final String INNER_PROXY = "innerProxy";
Expand All @@ -62,21 +61,10 @@ public class FederatedStoreRecursionIT extends AbstractStoreIT {
public static final String ENT_GROUP = "ent1";
public static final String PROPERTY_NAME = "count";
private Graph proxyToRestServiceFederatedGraph;
private User user = new User();

@Before
public void setUp() throws Exception {
graph.execute(new RemoveGraph.Builder()
.graphId(PublicAccessPredefinedFederatedStore.ACCUMULO_GRAPH_WITH_EDGES)
.build(), user);
graph.execute(new RemoveGraph.Builder()
.graphId(PublicAccessPredefinedFederatedStore.ACCUMULO_GRAPH_WITH_ENTITIES)
.build(), user);

graph = null;
}


@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void shouldNotInfinityLoopWhenAddingElements() throws Exception {
/*
* Structure:
Expand All @@ -89,6 +77,7 @@ public void shouldNotInfinityLoopWhenAddingElements() throws Exception {
* v |
* innerProxy -------->
*/
CacheServiceLoader.shutdown();

createProxyToRestServiceFederatedGraph();
createTheInnerFederatedStore();
Expand Down
Expand Up @@ -17,7 +17,7 @@
package uk.gov.gchq.gaffer.federatedstore.integration;

import com.google.common.collect.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties;
import uk.gov.gchq.gaffer.commonutil.StreamUtil;
Expand Down Expand Up @@ -49,7 +49,7 @@
* In all of theses tests the Federated graph contains two graphs, one containing
* a schema with only edges the other with only entities.
*/
public class FederatedViewsIT extends AbstractStoreIT {
public class FederatedViewsIT extends AbstractStandaloneFederatedStoreIT {

public static final String BASIC_EDGE = "BasicEdge";
public static final String BASIC_ENTITY = "BasicEntity";
Expand All @@ -60,7 +60,7 @@ public class FederatedViewsIT extends AbstractStoreIT {

@Override
protected Schema createSchema() {
final Schema.Builder schemaBuilder = new Schema.Builder(createDefaultSchema());
final Schema.Builder schemaBuilder = new Schema.Builder(AbstractStoreIT.createDefaultSchema());
schemaBuilder.edges(Collections.EMPTY_MAP);
schemaBuilder.entities(Collections.EMPTY_MAP);
schemaBuilder.json(StreamUtil.openStream(FederatedViewsIT.class, "schema/basicEdgeSchema.json"));
Expand Down
Expand Up @@ -54,7 +54,7 @@
public class FederatedAggregateHandlerTest {

private static Class currentClass = new Object() { }.getClass().getEnclosingClass();
private static final AccumuloProperties PROPERTIES = AccumuloProperties.loadStoreProperties(StreamUtil.openStream(currentClass, "properties/accumuloStore.properties"));
private static final AccumuloProperties PROPERTIES = AccumuloProperties.loadStoreProperties(StreamUtil.openStream(currentClass, "properties/singleUseAccumuloStore.properties"));

@Test
public void shouldDelegateToHandler() throws OperationException {
Expand Down Expand Up @@ -89,10 +89,13 @@ public void shouldAggregateDuplicatesFromDiffStores() throws Exception {
.storeProperties(federatedStoreProperties)
.build();

final String graphNameA = "a";
final String graphNameB = "b";

final Context context = new Context(new User());
fed.execute(new OperationChain.Builder()
.first(new AddGraph.Builder()
.graphId("a")
.graphId(graphNameA)
.schema(new Schema.Builder()
.edge("edge", new SchemaEdgeDefinition.Builder()
.source("string")
Expand All @@ -103,7 +106,7 @@ public void shouldAggregateDuplicatesFromDiffStores() throws Exception {
.storeProperties(PROPERTIES)
.build())
.then(new AddGraph.Builder()
.graphId("b")
.graphId(graphNameB)
.schema(new Schema.Builder()
.edge("edge", new SchemaEdgeDefinition.Builder()
.source("string")
Expand All @@ -121,7 +124,7 @@ public void shouldAggregateDuplicatesFromDiffStores() throws Exception {
.source("s1")
.dest("d1")
.build())
.option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "a")
.option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameA)
.build(), context);

fed.execute(new AddElements.Builder()
Expand All @@ -130,7 +133,7 @@ public void shouldAggregateDuplicatesFromDiffStores() throws Exception {
.source("s1")
.dest("d1")
.build())
.option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "b")
.option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameB)
.build(), context);

final CloseableIterable<? extends Element> getAll = fed.execute(new GetAllElements(), context);
Expand Down

0 comments on commit 0531595

Please sign in to comment.