Skip to content

Commit

Permalink
Add asserts to Lucene modify test #267
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-austin committed Apr 4, 2022
1 parent 07a42a3 commit 64d1af5
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/test/java/org/icatproject/core/manager/TestLucene.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ public QueueItem(String entityName, Long id, String json) {

@Test
public void modify() throws IcatException {
Queue<QueueItem> queue = new ConcurrentLinkedQueue<>();

ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (JsonGenerator gen = Json.createGenerator(baos)) {
gen.writeStartArray();
Expand All @@ -101,16 +99,53 @@ public void modify() throws IcatException {
luceneApi.encodeStringField(gen, "dataset", 2001L);
gen.writeEnd();
}
String elephantJson = baos.toString();

String json = baos.toString();
baos = new ByteArrayOutputStream();
try (JsonGenerator gen = Json.createGenerator(baos)) {
gen.writeStartArray();
luceneApi.encodeTextField(gen, "text", "Rhinos and Aardvarks");
luceneApi.encodeStringField(gen, "startDate", new Date());
luceneApi.encodeStringField(gen, "endDate", new Date());
luceneApi.encodeStoredId(gen, 42L);
luceneApi.encodeStringField(gen, "dataset", 2001L);
gen.writeEnd();
}
String rhinoJson = baos.toString();

queue.add(new QueueItem("Datafile", null, json));
JsonObject elephantQuery = SearchApi.buildQuery("Datafile", null, "elephant", null, null, null, null, null);
JsonObject rhinoQuery = SearchApi.buildQuery("Datafile", null, "rhino", null, null, null, null, null);

queue.add(new QueueItem("Datafile", 42L, json));
Queue<QueueItem> queue = new ConcurrentLinkedQueue<>();
queue.add(new QueueItem("Datafile", null, elephantJson));
modifyQueue(queue);
checkLsr(luceneApi.getResults(elephantQuery, 5), 42L);
checkLsr(luceneApi.getResults(rhinoQuery, 5));

queue = new ConcurrentLinkedQueue<>();
queue.add(new QueueItem("Datafile", 42L, rhinoJson));
modifyQueue(queue);
checkLsr(luceneApi.getResults(elephantQuery, 5));
checkLsr(luceneApi.getResults(rhinoQuery, 5), 42L);

queue = new ConcurrentLinkedQueue<>();
queue.add(new QueueItem("Datafile", 42L, null));
queue.add(new QueueItem("Datafile", 42L, null));
modifyQueue(queue);
checkLsr(luceneApi.getResults(elephantQuery, 5));
checkLsr(luceneApi.getResults(rhinoQuery, 5));

queue = new ConcurrentLinkedQueue<>();
queue.add(new QueueItem("Datafile", null, elephantJson));
queue.add(new QueueItem("Datafile", 42L, rhinoJson));
queue.add(new QueueItem("Datafile", 42L, null));
queue.add(new QueueItem("Datafile", 42L, null));
modifyQueue(queue);
checkLsr(luceneApi.getResults(elephantQuery, 5));
checkLsr(luceneApi.getResults(rhinoQuery, 5));
}

private void modifyQueue(Queue<QueueItem> queue) throws IcatException {
Iterator<QueueItem> qiter = queue.iterator();
if (qiter.hasNext()) {
StringBuilder sb = new StringBuilder("[");
Expand Down Expand Up @@ -138,8 +173,8 @@ public void modify() throws IcatException {
logger.debug("XXX " + sb.toString());

luceneApi.modify(sb.toString());
luceneApi.commit();
}

}

private void addDocuments(String entityName, String json) throws IcatException {
Expand Down

0 comments on commit 64d1af5

Please sign in to comment.