use of org.springframework.batch.item.ExecutionContext in project jvarkit by lindenb.
the class VariantContextBatchWriter method open.
@Override
public void open(final ExecutionContext executionContext) throws ItemStreamException {
if (this.filenameFactory == null)
throw new ItemStreamException("resource is not defined");
try {
final String filename = this.filenameFactory.apply(executionContext);
if (StringUtil.isBlank(filename))
throw new ItemStreamException("No output file defined.");
if (LOG.isInfoEnabled())
LOG.info("Opening " + filename + " for writing");
if (!Arrays.stream(IOUtil.VCF_EXTENSIONS).anyMatch(SUFF -> filename.endsWith(SUFF))) {
throw new ItemStreamException("Bad extension for a VCF file:" + filename);
}
final File vcfFile = new File(filename);
VCFHeader header = SpringBatchUtils.getVcfHeader(executionContext);
final VariantContextWriterBuilder vcwb = new VariantContextWriterBuilder();
vcwb.setOutputFile(vcfFile);
if (this.reference != null) {
final SAMSequenceDictionary dic = SAMSequenceDictionaryExtractor.extractDictionary(this.reference);
vcwb.setReferenceDictionary(dic);
if (header.getSequenceDictionary() == null) {
header = new VCFHeader(header);
header.setSequenceDictionary(dic);
}
} else {
vcwb.setReferenceDictionary(header.getSequenceDictionary());
}
vcwb.setCreateMD5(this.createMD5);
this.vcw = vcwb.build();
this.vcw.writeHeader(header);
} catch (final Exception err) {
priv_close();
throw new ItemStreamException(err);
}
}
use of org.springframework.batch.item.ExecutionContext in project pinpoint by naver.
the class DefaultDividerTest method devide.
@Test
public void devide() {
DefaultDivider defaultDivider = new DefaultDivider();
Map<String, ExecutionContext> map = defaultDivider.divide("test_partition", "test");
assertEquals(1, map.size());
}
use of org.springframework.batch.item.ExecutionContext in project pinpoint by naver.
the class AlarmReaderTest method readTest3.
@Test
public void readTest3() {
StepExecution stepExecution = new StepExecution("alarmStep", null);
ExecutionContext executionContext = new ExecutionContext();
stepExecution.setExecutionContext(executionContext);
AlarmServiceImpl alarmService = new AlarmServiceImpl(mock(AlarmDao.class), mock(WebhookSendInfoDao.class)) {
@Override
public List<Rule> selectRuleByApplicationId(String applicationId) {
return new LinkedList<>();
}
};
AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmService);
reader.beforeStep(stepExecution);
assertNull(reader.read());
}
use of org.springframework.batch.item.ExecutionContext in project pinpoint by naver.
the class ReaderTest method readTest2.
@Test
public void readTest2() {
StepExecution stepExecution = new StepExecution("alarmStep", null);
ExecutionContext executionContext = new ExecutionContext();
executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 2);
stepExecution.setExecutionContext(executionContext);
AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmService);
reader.beforeStep(stepExecution);
for (int i = 0; i < 2; i++) {
assertNotNull(reader.read());
}
assertNull(reader.read());
}
use of org.springframework.batch.item.ExecutionContext in project pinpoint by naver.
the class ReaderTest method readTest.
@Test
public void readTest() {
StepExecution stepExecution = new StepExecution("alarmStep", null);
ExecutionContext executionContext = new ExecutionContext();
executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 1);
stepExecution.setExecutionContext(executionContext);
AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmService);
reader.beforeStep(stepExecution);
for (int i = 0; i < 5; i++) {
assertNotNull(reader.read());
}
assertNull(reader.read());
}
Aggregations