streamBuilder.setLocal(false);
streamBuilder.addField("x", Type.getPrimitive(Type.TypeName.STRING));
streamBuilder.addField("y", Type.getPrimitive(Type.TypeName.INT));
getSymbolTable().addSymbol(streamBuilder.build());
LocalEnvironment env = getEnvironment();
env.connect();
// Test the first query.
LOG.debug("Running first query");
getConf().set(SelectStmt.CLIENT_SELECT_TARGET_KEY, "select-out");
QuerySubmitResponse selectResponse1 = env.submitQuery(
"SELECT * FROM inputstream",
getQueryOpts());
assertNotNull(selectResponse1);
FlowId queryId1 = selectResponse1.getFlowId();
assertNotNull(queryId1);
// Put some data into the stream.
BufferedWriter w = new BufferedWriter(new FileWriter(sourceFile));
try {
w.write("line1,1\n");
w.write("line2,2\n");
w.write("line3,3\n");
} finally {
w.close();
}
MemoryOutputElement output1 = getOutput("select-out");
assertNotNull(output1);
SelectableList<GenericData.Record> outRecords1 = output1.getRecords();
synchronized (outRecords1) {
while (outRecords1.size() < 3) {
outRecords1.wait();
}
for(GenericData.Record r : outRecords1) {
LOG.debug("query 1 got " + r.get("x"));
}
this.assertRecordExists(outRecords1, "x", new Utf8("line1"));
this.assertRecordExists(outRecords1, "x", new Utf8("line2"));
this.assertRecordExists(outRecords1, "x", new Utf8("line3"));
}
LOG.debug("first query SUCCESS");
if (killFirstQuery) {
LOG.debug("Canceling first query");
env.cancelFlow(queryId1);
joinFlow(queryId1);
LOG.debug("First query canceled.");
}
// Test the second query.
LOG.debug("Running second query");
getConf().set(SelectStmt.CLIENT_SELECT_TARGET_KEY, "select-out2");
QuerySubmitResponse selectResponse2 = env.submitQuery(
"SELECT * FROM inputstream WHERE y = 6",
getQueryOpts());
assertNotNull(selectResponse2);
FlowId queryId2 = selectResponse2.getFlowId();
assertNotNull(queryId2);
// Add more data to the stream.
w = new BufferedWriter(new FileWriter(sourceFile, true));
try {
w.write("line4,4\n");
w.write("line5,5\n");
w.write("line6,6\n");
} finally {
w.close();
}
MemoryOutputElement output2 = getOutput("select-out2");
assertNotNull(output2);
SelectableList<GenericData.Record> outRecords2 = output2.getRecords();
synchronized (outRecords2) {
while (outRecords2.size() < 1) {
outRecords2.wait();
}
for(GenericData.Record r : outRecords2) {
LOG.debug("query 2 got " + r.get("x"));
}
this.assertRecordFields(outRecords2, "y", Integer.valueOf(6), "x", new Utf8("line6"));
}
LOG.debug("second query SUCCESS");
if (!killFirstQuery) {
// Double check to ensure that the first query received those additional records.
synchronized (outRecords1) {
while (outRecords1.size() < 6) {
outRecords1.wait();
}
for(GenericData.Record r : outRecords1) {
LOG.debug("second time around, query 1 got " + r.get("x"));
}
this.assertRecordExists(outRecords1, "x", new Utf8("line4"));
this.assertRecordExists(outRecords1, "x", new Utf8("line5"));
this.assertRecordExists(outRecords1, "x", new Utf8("line6"));
}
LOG.debug("first query CONTINUED SUCCESS");
LOG.debug("Now we're killing the first query.");
env.cancelFlow(queryId1);
joinFlow(queryId1);
}
LOG.debug("Killing 2nd query.");
env.cancelFlow(queryId2);
joinFlow(queryId2);
}