use of uk.gov.gchq.gaffer.hdfs.operation.AddElementsFromHdfs in project Gaffer by gchq.
the class AccumuloAddElementsFromHdfsJobFactoryTest method shouldSetNoMoreThanMaxNumberOfReducersSpecified.
@Test
public void shouldSetNoMoreThanMaxNumberOfReducersSpecified() throws IOException, StoreException, OperationException {
// Given
store.initialise("graphId", SCHEMA, PROPERTIES);
final JobConf localConf = createLocalConf();
final FileSystem fs = FileSystem.getLocal(localConf);
fs.mkdirs(new Path(outputDir));
fs.mkdirs(new Path(splitsDir));
final BufferedWriter writer = new BufferedWriter(new FileWriter(splitsFile.toString()));
for (int i = 100; i < 200; i++) {
writer.write(i + "\n");
}
writer.close();
final SplitStoreFromFile splitTable = new SplitStoreFromFile.Builder().inputPath(splitsFile.toString()).build();
store.execute(splitTable, new Context(new User()));
final AccumuloAddElementsFromHdfsJobFactory factory = getJobFactory();
final Job job = Job.getInstance(localConf);
// When
AddElementsFromHdfs operation = new AddElementsFromHdfs.Builder().outputPath(outputDir.toString()).addInputMapperPair(inputDir.toString(), TextMapperGeneratorImpl.class.getName()).maxReducers(10).splitsFilePath("target/data/splits.txt").build();
factory.setupJob(job, operation, TextMapperGeneratorImpl.class.getName(), store);
// Then
assertTrue(job.getNumReduceTasks() <= 10);
// When
operation = new AddElementsFromHdfs.Builder().outputPath(outputDir.toString()).addInputMapperPair(inputDir.toString(), TextMapperGeneratorImpl.class.getName()).maxReducers(100).splitsFilePath("target/data/splits.txt").build();
factory.setupJob(job, operation, TextMapperGeneratorImpl.class.getName(), store);
// Then
assertTrue(job.getNumReduceTasks() <= 100);
// When
operation = new AddElementsFromHdfs.Builder().outputPath(outputDir.toString()).addInputMapperPair(inputDir.toString(), TextMapperGeneratorImpl.class.getName()).maxReducers(1000).splitsFilePath("target/data/splits.txt").build();
factory.setupJob(job, operation, TextMapperGeneratorImpl.class.getName(), store);
// Then
assertTrue(job.getNumReduceTasks() <= 1000);
}
use of uk.gov.gchq.gaffer.hdfs.operation.AddElementsFromHdfs in project Gaffer by gchq.
the class AccumuloAddElementsFromHdfsJobFactoryTest method setupAccumuloPartitionerWithGivenPartitioner.
private void setupAccumuloPartitionerWithGivenPartitioner(final Class<? extends Partitioner> partitioner) throws IOException {
// Given
final JobConf localConf = createLocalConf();
final FileSystem fs = FileSystem.getLocal(localConf);
fs.mkdirs(new Path(outputDir));
fs.mkdirs(new Path(splitsDir));
try (final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fs.create(new Path(splitsFile))))) {
writer.write("1");
}
final AccumuloAddElementsFromHdfsJobFactory factory = getJobFactory();
final Job job = mock(Job.class);
final AddElementsFromHdfs operation = new AddElementsFromHdfs.Builder().outputPath(outputDir).partitioner(partitioner).useProvidedSplits(true).splitsFilePath(splitsFile).build();
final AccumuloStore store = mock(AccumuloStore.class);
given(job.getConfiguration()).willReturn(localConf);
// When
factory.setupJob(job, operation, TextMapperGeneratorImpl.class.getName(), store);
// Then
if (NoPartitioner.class.equals(partitioner)) {
verify(job, never()).setNumReduceTasks(Mockito.anyInt());
verify(job, never()).setPartitionerClass(Mockito.any(Class.class));
assertNull(job.getConfiguration().get(GafferRangePartitioner.class.getName() + ".cutFile"));
} else {
verify(job).setNumReduceTasks(2);
verify(job).setPartitionerClass(GafferKeyRangePartitioner.class);
assertEquals(splitsFile, job.getConfiguration().get(GafferRangePartitioner.class.getName() + ".cutFile"));
}
}
Aggregations