use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testEntityIdQueryEntitiesOnly.
private void testEntityIdQueryEntitiesOnly(final AccumuloStore store) throws StoreException {
setupGraph(store, NUM_ENTRIES);
final User user = new User();
// Create set to query for
final Set<ElementId> ids = new HashSet<>();
for (int i = 0; i < NUM_ENTRIES; i++) {
ids.add(new EntitySeed("" + i));
}
final View view = new View.Builder().entity(TestGroups.ENTITY).build();
AccumuloSingleIDRetriever retriever = null;
final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (final IteratorSettingException e) {
throw new RuntimeException(e);
}
// Should find only the entities i
assertEquals(NUM_ENTRIES, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class CreateSplitPointsTest method shouldAddElementsFromHdfs.
@Test
public void shouldAddElementsFromHdfs() throws Exception {
// Given
createInputFile();
final SingleUseAccumuloStoreWithTabletServers store = new SingleUseAccumuloStoreWithTabletServers();
store.initialise("graphId1", Schema.fromJson(StreamUtil.schemas(getClass())), PROPERTIES);
final Graph graph = new Graph.Builder().store(store).build();
// When
graph.execute(new OperationChain.Builder().first(new SampleDataForSplitPoints.Builder().jobInitialiser(new TextJobInitialiser()).addInputMapperPair(inputDir, TextMapperGeneratorImpl.class.getName()).outputPath(outputDir).proportionToSample(1f).validate(true).mappers(5).splitsFilePath(splitsFile).compressionCodec(null).build()).then(new SplitStoreFromFile.Builder().inputPath(splitsFile).build()).build(), new User());
// Then
final List<Text> splitsOnTable = Lists.newArrayList(store.getConnection().tableOperations().listSplits(store.getTableName(), 10));
final List<String> stringSplitsOnTable = Lists.transform(splitsOnTable, t -> StringUtil.toString(t.getBytes()));
final List<String> fileSplitsDecoded = new ArrayList<>();
BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(new Path(splitsFile))));
while (br.ready()) {
fileSplitsDecoded.add(new String(Base64.decodeBase64(br.readLine())));
}
assertThat(stringSplitsOnTable).isEqualTo(fileSplitsDecoded);
assertThat(splitsOnTable).hasSize(2);
assertThat(stringSplitsOnTable.get(0)).isEqualTo(VERTEX_ID_PREFIX + "53\u0000\u0001");
assertThat(stringSplitsOnTable.get(1)).isEqualTo(VERTEX_ID_PREFIX + "99\u0000\u0001");
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class CountAllElementsDefaultViewHandler method doOperation.
private Long doOperation(final Context context, final MapStore mapStore) {
final User user = context.getUser();
final Schema schema = mapStore.getSchema();
final boolean supportsVisibility = mapStore.getTraits().contains(StoreTrait.VISIBILITY);
Stream<Element> elementStream = Stream.concat(mapStore.getMapImpl().getAllAggElements(schema.getGroups()), mapStore.getMapImpl().getAllNonAggElements(schema.getGroups()));
if (supportsVisibility) {
elementStream = GetElementsUtil.applyVisibilityFilter(elementStream, schema, user);
}
return elementStream.count();
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class GetElementsHandlerTest method shouldReturnHBaseRetrieverWithIncludeMatchedVertexWhenSeedMatchingIsNull.
@Test
public void shouldReturnHBaseRetrieverWithIncludeMatchedVertexWhenSeedMatchingIsNull() throws OperationException, StoreException {
// Given
final Iterable<EntityId> ids = mock(Iterable.class);
final Context context = mock(Context.class);
final User user = mock(User.class);
final HBaseStore store = mock(HBaseStore.class);
final HBaseRetriever<GetElements> hbaseRetriever = mock(HBaseRetriever.class);
final GetElementsHandler handler = new GetElementsHandler();
final GetElements getElements = new GetElements.Builder().inputIds(ids).seedMatching(null).build();
given(context.getUser()).willReturn(user);
given(store.createRetriever(getElements, user, ids, true)).willReturn(hbaseRetriever);
// When
final HBaseRetriever<GetElements> result = (HBaseRetriever<GetElements>) handler.doOperation(getElements, context, store);
// Then
assertSame(hbaseRetriever, result);
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class GetElementsHandlerTest method shouldReturnHBaseRetrieverWithoutIncludeMatchdxVertex.
@Test
public void shouldReturnHBaseRetrieverWithoutIncludeMatchdxVertex() throws OperationException, StoreException {
// Given
final Iterable<EntityId> ids = mock(Iterable.class);
final Context context = mock(Context.class);
final User user = mock(User.class);
final HBaseStore store = mock(HBaseStore.class);
final HBaseRetriever<GetElements> hbaseRetriever = mock(HBaseRetriever.class);
final GetElementsHandler handler = new GetElementsHandler();
final GetElements getElements = new GetElements.Builder().inputIds(ids).seedMatching(SeedMatching.SeedMatchingType.EQUAL).build();
given(context.getUser()).willReturn(user);
given(store.createRetriever(getElements, user, ids, false)).willReturn(hbaseRetriever);
// When
final HBaseRetriever<GetElements> result = (HBaseRetriever<GetElements>) handler.doOperation(getElements, context, store);
// Then
assertSame(hbaseRetriever, result);
}
Aggregations