Skip to content

Commit

Permalink
Integration test of simple UBI setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Nov 13, 2024
1 parent d1e215e commit 47d57ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class LoggingStream extends TupleStream implements Expressible {
// field name in summary tuple for #docs updated in batch
public static String BATCH_LOGGED_FIELD_NAME = "batchLogged";

private StreamContext context;
private Path chroot;

/**
Expand Down Expand Up @@ -139,12 +138,6 @@ public void open() throws IOException {
SolrException.ErrorCode.BAD_REQUEST, "file to log to must be under " + chroot);
}

// if (!Files.exists(filePath)) {
//
// throw new SolrException(
// SolrException.ErrorCode.BAD_REQUEST,
// "file/directory to stream doesn't exist: " + crawlRootStr);
// }
fos = new FileOutputStream(filePath.toFile());
writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8);

Expand Down Expand Up @@ -204,9 +197,6 @@ private StreamExpression toExpression(StreamFactory factory, boolean includeStre
throws IOException {
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
expression.addParameter(filepath);
// expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
// expression.addParameter(
// new StreamExpressionNamedParameter("batchSize", Integer.toString(updateBatchSize)));

if (includeStreams) {
if (tupleSource != null) {
Expand Down Expand Up @@ -247,7 +237,6 @@ public Explanation toExplanation(StreamFactory factory) throws IOException {

@Override
public void setStreamContext(StreamContext context) {
this.context = context;
Object solrCoreObj = context.get("solr-core");
if (solrCoreObj == null || !(solrCoreObj instanceof SolrCore)) {
throw new SolrException(
Expand All @@ -271,16 +260,6 @@ public void setStreamContext(StreamContext context) {
this.tupleSource.setStreamContext(context);
}

private void verifyCollectionName(String collectionName, StreamExpression expression)
throws IOException {
if (null == collectionName) {
throw new IOException(
String.format(
Locale.ROOT,
"invalid expression %s - collectionName expected as first operand",
expression));
}
}

// private SolrInputDocument convertTupleTJson(Tuple tuple) {
// SolrInputDocument doc = new SolrInputDocument();
Expand All @@ -307,7 +286,7 @@ private void addMultivaluedField(SolrInputDocument doc, String fieldName, List<?
}

/**
* This method will be called on every batch of tuples comsumed, after converting each tuple in
* This method will be called on every batch of tuples consumed, after converting each tuple in
* that batch to a Solr Input Document.
*/
protected void uploadBatchToCollection(Tuple doc) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public void inform(SolrCore core) {
CoreContainer coreContainer = core.getCoreContainer();
SolrClientCache solrClientCache = coreContainer.getSolrClientCache();

// do I need this check?
if (initArgs != null) {
log.info("Initializing UBIComponent");
if (coreContainer.isZooKeeperAware()) {
Expand All @@ -157,7 +156,7 @@ public void inform(SolrCore core) {
log.info(
"No 'ubiQueryStreamProcessingExpression' file provided to describe processing of UBI query information.");
log.info(
"Writing out UBI query information to local log file ubi_queries.jsonl instead.");
"Writing out UBI query information to local $SOLR_HOME/userfiles/ubi_queries.jsonl file instead.");
expr = "logging(ubi_queries.jsonl," + "tuple(id=49,a_i=1,b_i=5)" + ")";
} else {
LineNumberReader bufferedReader;
Expand Down Expand Up @@ -289,6 +288,9 @@ protected void processIds(
List<Tuple> tuples = getTuples(stream);
log.error("Here are the tuples (" + tuples.size() + "):" + tuples);
}
else {
log.error("UBI Query Stream is null, can't log query information.");
}
}

protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {
Expand Down
36 changes: 8 additions & 28 deletions solr/packaging/test/test_ubi.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ teardown() {
save_home_on_failure

delete_all_collections
SOLR_STOP_WAIT=1 solr stop -all >/dev/null 2>&1
SOLR_STOP_WAIT=1 solr stop --all >/dev/null 2>&1
}

@test "Run set up process" {
Expand All @@ -48,7 +48,7 @@ teardown() {

assert_output --partial '"status":0'

curl -X POST -H 'Content-type:application/json' -d '{
run curl -X POST -H 'Content-type:application/json' -d '{
"update-requesthandler": {
"name": "/select",
"class": "solr.SearchHandler",
Expand All @@ -58,7 +58,7 @@ teardown() {

assert_output --partial '"status":0'

curl -X POST -H 'Content-type:application/json' -d '{
run curl -X POST -H 'Content-type:application/json' -d '{
"update-requesthandler": {
"name": "/query",
"class": "solr.SearchHandler",
Expand All @@ -72,31 +72,11 @@ teardown() {
run curl "http://localhost:${SOLR_PORT}/solr/techproducts/select?q=*:*&rows=3&ubi=true"
assert_output --partial '"status":0'
assert_output --partial '"query_id":"1234'


# Rich UBI user query tracking enabled query
run curl -X POST -H 'Content-type:application/json' -d '{
"query" : "ram OR memory",
"filter": [
"inStock:true"
],
"limit":2,
"params": {
"ubi": "true",
"query_id": "xyz890",
"user_query": {
"query": "RAM memory",
"experiment": "supersecret",
"page": 1,
"filter": "productStatus:available"
}
}
}' "http://localhost:${SOLR_PORT}/solr/techproducts/query"
assert_output --partial '"query_id":"xyz890"'


# No luck on getting the logs to read.
#run cat "${SOLR_LOGS_DIR}/solr.log"
#run tail -n 1 "${SOLR_LOGS_DIR}/ubi_queries.jsonl"
#assert_output --partial "inStock:false"
#assert_file_contains "${SOLR_LOGS_DIR}/ubi_queries.jsonl" 'eric'
assert_file_exist ${SOLR_TIP}/example/techproducts/solr/userfiles/ubi_queries.jsonl
run tail -n 1 "${SOLR_TIP}/example/techproducts/solr/userfiles/ubi_queries.jsonl"
assert_output --partial '{"id":"49","a_i":"1","b_i":"5"}'
assert_file_contains "${SOLR_TIP}/example/techproducts/solr/userfiles/ubi_queries.jsonl" '{"id":"49","a_i":"1","b_i":"5"}'
}

0 comments on commit 47d57ea

Please sign in to comment.