Map<String, String> channelContext = new HashMap();
channelContext.put("capacity", "1000000");
channelContext.put("keep-alive", "0"); // for faster tests
Channel channel = new MemoryChannel();
channel.setName(channel.getClass().getName() + SEQ_NUM.getAndIncrement());
Configurables.configure(channel, new Context(channelContext));
class MySolrSink extends MorphlineSolrSink {
public MySolrSink(MorphlineHandlerImpl indexer) {
super(indexer);
}
}
int batchSize = SEQ_NUM2.incrementAndGet() % 2 == 0 ? 100 : 1;
DocumentLoader testServer = new SolrServerDocumentLoader(solrServer, batchSize);
MorphlineContext solrMorphlineContext = new SolrMorphlineContext.Builder()
.setDocumentLoader(testServer)
.setExceptionHandler(new FaultTolerance(false, false, SolrServerException.class.getName()))
.setMetricRegistry(new MetricRegistry()).build();
MorphlineHandlerImpl impl = new MorphlineHandlerImpl();
impl.setMorphlineContext(solrMorphlineContext);
class MySolrLocator extends SolrLocator { // trick to access protected ctor
public MySolrLocator(MorphlineContext indexer) {
super(indexer);
}
}
SolrLocator locator = new MySolrLocator(solrMorphlineContext);
locator.setSolrHomeDir(testSolrHome + "/collection1");
String str1 = "SOLR_LOCATOR : " + locator.toString();
//File solrLocatorFile = new File("target/test-classes/test-morphlines/solrLocator.conf");
//String str1 = Files.toString(solrLocatorFile, Charsets.UTF_8);
File morphlineFile = new File("target/test-classes/test-morphlines/solrCellDocumentTypes.conf");
String str2 = Files.toString(morphlineFile, Charsets.UTF_8);
tmpFile = File.createTempFile("morphline", ".conf");
tmpFile.deleteOnExit();
Files.write(str1 + "\n" + str2, tmpFile, Charsets.UTF_8);
context.put("morphlineFile", tmpFile.getPath());
impl.configure(new Context(context));
sink = new MySolrSink(impl);
sink.setName(sink.getClass().getName() + SEQ_NUM.getAndIncrement());
sink.configure(new Context(context));
sink.setChannel(channel);
sink.start();
source = new EmbeddedSource(sink);
ChannelSelector rcs = new ReplicatingChannelSelector();
rcs.setChannels(Collections.singletonList(channel));
ChannelProcessor chp = new ChannelProcessor(rcs);
Context chpContext = new Context();
chpContext.put("interceptors", "uuidinterceptor");
chpContext.put("interceptors.uuidinterceptor.type", UUIDInterceptor.Builder.class.getName());
chp.configure(chpContext);
source.setChannelProcessor(chp);
deleteAllDocuments();
}