Skip to content

Commit

Permalink
Merge release into master branch (#3331)
Browse files Browse the repository at this point in the history
  • Loading branch information
j69772 authored Nov 1, 2024
2 parents 1345483 + d265a92 commit 31abc0e
Show file tree
Hide file tree
Showing 152 changed files with 7,610 additions and 558 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration-legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Accumulo
values: :accumulo-store,:accumulo-rest
- name: Federated-And-Map
values: :integration-test,:federated-store,:map-store,:map-rest
values: :integration-test,:federated-store,:map-store,:map-rest,:simple-federated-store
- name: REST
values: :rest-api,:common-rest,:spring-rest,:core-rest,:store-implementation,:proxy-store
- name: Examples
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
- name: Accumulo
values: :accumulo-store,:accumulo-rest
- name: Federated-And-Map
values: :integration-test,:federated-store,:map-store,:map-rest
values: :integration-test,:federated-store,:map-store,:map-rest,:simple-federated-store
- name: REST
values: :rest-api,:common-rest,:spring-rest,:core-rest,:store-implementation,:proxy-store
- name: Examples
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Crown Copyright
* Copyright 2017-2024 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 @@ -117,14 +117,10 @@ public void removeAnyItem() {
}

public int size() {
if (null == collection) {
if (null != singleItem) {
return 1;
}
return 0;
if (collection != null) {
return collection.size();
}

return collection.size();
return (singleItem != null) ? 1 : 0;
}

public boolean isEmpty() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Crown Copyright
* Copyright 2017-2024 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 @@ -39,6 +39,11 @@ public class ElementVisibility {
EMPTY_NODE = new ElementVisibility.Node(ElementVisibility.NodeType.EMPTY, 0);
}

public ElementVisibility(final Object expression) {
this.node = null;
this.validate(convert(expression));
}

public ElementVisibility(final String expression) {
this(expression.getBytes(UTF_8));
}
Expand All @@ -48,6 +53,10 @@ public ElementVisibility(final byte[] expression) {
this.validate(expression);
}

private byte[] convert(final Object expression) {
return expression.toString().getBytes(UTF_8);
}

public byte[] getExpression() {
return this.expression;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Crown Copyright
* Copyright 2017-2024 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,20 +86,28 @@ public boolean add(final E e) {
boolean result = false;

final OneOrMore<E> values = backingMap.get(e);
// Skip the item if we are deduplicating and the item already exists
// Skip the item if we are deduplicating and the item already exists.
boolean skipItem = (deduplicate && nonNull(values) && values.contains(e));
if (!skipItem) {
if (nonNull(limit) && size >= limit) {
// Check the item against the last item.
final Map.Entry<E, OneOrMore<E>> last = backingMap.lastEntry();
// Checks if the last items key is greater than e
if (0 < comparator.compare(last.getKey(), e)) {
// Checks if the items value contains a collection or a single item
if (1 < last.getValue().size()) {
// Items value contains a collection.
// Remove item from collection.
last.getValue().removeAnyItem();
} else {
// Items value contains a single item.
// Remove item from backingMap.
backingMap.remove(last.getKey());
}
size--;
// e is bigger than the lastEntry.
} else {
// Skip adding the item.
skipItem = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

public final class OtelUtil {

public static final String USER_ATTRIBUTE = "enduser.id";
public static final String JOB_ID_ATTRIBUTE = "gaffer.jobId";
public static final String GRAPH_ID_ATTRIBUTE = "gaffer.graphId";
public static final String VIEW_ATTRIBUTE = "gaffer.view";
public static final String GREMLIN_QUERY_ATTRIBUTE = "gaffer.gremlin.query";

private static boolean openTelemetryActive = false;

private OtelUtil() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Crown Copyright
* Copyright 2017-2024 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 @@ -24,7 +24,6 @@
import java.util.stream.IntStream;

import static org.assertj.core.api.Assertions.assertThat;

public class OneOrMoreTest {

@Test
Expand Down Expand Up @@ -72,6 +71,32 @@ public void shouldRemoveLastItemInList() {
.containsExactly(1, 2);
}

@Test
void testSizeWithNonNullCollection() {
final boolean deduplicate = true;
final OneOrMore<Integer> collection = new OneOrMore<>(deduplicate, 1);
collection.add(2);
collection.add(3);

assertThat(collection).hasSize(3);
}

@Test
void testSizeWithSingleItem() {
final boolean deduplicate = true;
final OneOrMore<Integer> collection = new OneOrMore<>(deduplicate, 1);

assertThat(collection).hasSize(1);
}

@Test
void testSizeWithNullCollectionAndSingleItem() {
final boolean deduplicate = true;
final OneOrMore<Integer> collection = new OneOrMore<>(deduplicate, null);

assertThat(collection).isEmpty();
}

@Test
public void shouldAddItemsWithoutDeduplicate() {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@

class ElementVisibilityTest {

@Test
void testIntegerTypeIsAccepted() {
final ElementVisibility ev = new ElementVisibility(1);
assertThat(ev).hasToString("[1]");
}

@Test
void testCustomObjectIsAccepted() {
RandomObject randomObject = new RandomObject("Hello", 1);
final ElementVisibility ev = new ElementVisibility(randomObject);
assertThat(ev).hasToString("[hello]");
}

@Test
void testEmptyStringIsValid() {
final ElementVisibility a = new ElementVisibility(new byte[0]);
Expand Down Expand Up @@ -188,4 +201,19 @@ private void assertNode(final ElementVisibility.Node node, final ElementVisibili
}
);
}

class RandomObject {
private String randomString;
private Integer randomInteger;

RandomObject(String randomString, Integer randomInteger) {
this.randomString = randomString;
this.randomInteger = randomInteger;
}

@Override
public String toString() {
return "hello";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ void shouldLimitAndNotDeduplicateEntries() {
assertThat(list).containsExactly(1, 1, 2, 2);
}

@Test
void shouldInsertNewItemAndRemoveOldItemWhenlimitIsReachedAndNewItemIsLessThanLastEntry() {
final LimitedInMemorySortedIterable<Integer> list = new LimitedInMemorySortedIterable<Integer>(Comparator.naturalOrder(), 3, false);

list.add(3);
list.add(2);
list.add(3);
list.add(2);

assertThat(list).hasSize(3).containsExactly(2, 2, 3);
}

@Test
void shouldAddAll() {
final LimitedInMemorySortedIterable<Integer> itr = new LimitedInMemorySortedIterable<Integer>(Comparator.naturalOrder(), 100);
Expand Down
10 changes: 7 additions & 3 deletions core/graph/src/main/java/uk/gov/gchq/gaffer/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ private <O> GraphResult<O> _execute(final StoreExecuter<O> storeExecuter, final
Span span = OtelUtil.startSpan(
this.getClass().getName(),
"Graph Request: " + clonedOpChain.toOverviewString());
span.setAttribute("gaffer.graphId", getGraphId());
span.setAttribute("gaffer.jobId", clonedContext.getJobId());
span.setAttribute("gaffer.user", clonedContext.getUser().getUserId());
span.setAttribute(OtelUtil.GRAPH_ID_ATTRIBUTE, getGraphId());
span.setAttribute(OtelUtil.JOB_ID_ATTRIBUTE, clonedContext.getJobId());
span.setAttribute(OtelUtil.USER_ATTRIBUTE, clonedContext.getUser().getUserId());

O result = null;
// Sets the span to current so parent child spans are auto linked
Expand Down Expand Up @@ -520,6 +520,10 @@ public GraphLibrary getGraphLibrary() {
return store.getCaches();
}

public String getCreatedTime() {
return store.getCreatedTime();
}

@FunctionalInterface
private interface StoreExecuter<O> {
O execute(final OperationChain<O> operation, final Context context) throws OperationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private Collection<Operation> resolveNamedOperations(final Operation operation,
.getOperationChain(namedOperation.getParameters());
// Update the operation inputs and add operation chain to the updated list
OperationHandlerUtil.updateOperationInput(namedOperationChain, namedOperation.getInput());
namedOperationChain.setOptions(namedOperation.getOptions());

// Run again to resolve any nested operations in the chain before adding
namedOperationChain.updateOperations(resolveNamedOperations(namedOperationChain, user, depth + 1));
Expand Down
34 changes: 34 additions & 0 deletions core/graph/src/test/java/uk/gov/gchq/gaffer/graph/GraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import uk.gov.gchq.gaffer.store.TestTypes;
import uk.gov.gchq.gaffer.store.library.GraphLibrary;
import uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary;
import uk.gov.gchq.gaffer.store.operation.DeleteAllData;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
Expand All @@ -104,6 +105,8 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -117,6 +120,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.within;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -2687,6 +2691,31 @@ public void shouldNotExpandGlobalEdgesWhereNotPresentInSchema(@Mock final Store
assertNotNull(mergedView.getGlobalEdges().get(0).getPostAggregationFilter());

}
@Test
void shouldGetGraphCreatedTime() {
// Given
final Store store = new TestStoreImpl();
final Schema schema = new Schema.Builder().build();
Graph graph = new Graph.Builder()
.config(new GraphConfig.Builder()
.graphId(GRAPH_ID)
.build())
.storeProperties(StreamUtil.storeProps(getClass()))
.store(store)
.addSchema(schema)
.build();

// When
String graphCreatedTime = graph.getCreatedTime();

// Then
assertThat(graphCreatedTime)
.isNotNull()
.isInstanceOf(String.class);
assertThat(LocalDateTime.parse(graphCreatedTime))
.isInstanceOf(LocalDateTime.class)
.isCloseTo(LocalDateTime.now(), within(20, ChronoUnit.SECONDS));
}

public static class TestStoreImpl extends Store {
@Override
Expand Down Expand Up @@ -2719,6 +2748,11 @@ protected OperationHandler<? extends DeleteElements> getDeleteElementsHandler()
return null;
}

@Override
protected OperationHandler<DeleteAllData> getDeleteAllDataHandler() {
return null;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return new GetTraitsHandler(new HashSet<>(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.Store;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.operation.DeleteAllData;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
Expand Down Expand Up @@ -89,6 +90,11 @@ protected OperationHandler<? extends DeleteElements> getDeleteElementsHandler()
return null;
}

@Override
protected OperationHandler<DeleteAllData> getDeleteAllDataHandler() {
return null;
}

@Override
protected OutputOperationHandler<GetTraits, Set<StoreTrait>> getGetTraitsHandler() {
return mock(GetTraitsHandler.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Crown Copyright
* Copyright 2016-2024 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
Loading

0 comments on commit 31abc0e

Please sign in to comment.