Skip to content

Commit

Permalink
Some minor fixes.
Browse files Browse the repository at this point in the history
Done:
- fix variable name
- add thread syncing
  • Loading branch information
bnouwt committed Nov 7, 2024
1 parent d22c93e commit cc8545d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ public ReactKnowledgeInteraction(CommunicativeAct act, GraphPattern argument, Gr
}

public ReactKnowledgeInteraction(CommunicativeAct act, GraphPattern argument, GraphPattern result,
boolean anIsFullMatch) {
this(act, argument, result, null, false, anIsFullMatch, null);
boolean anIncludeMetaKIs) {
this(act, argument, result, null, false, anIncludeMetaKIs, null);
}

public ReactKnowledgeInteraction(CommunicativeAct act, GraphPattern argument, GraphPattern result, boolean anIsMeta,
boolean anIsFullMatch) {
this(act, argument, result, null, anIsMeta, anIsFullMatch, null);
boolean anIncludeMetaKIs) {
this(act, argument, result, null, anIsMeta, anIncludeMetaKIs, null);
}

public ReactKnowledgeInteraction(CommunicativeAct act, GraphPattern argument, GraphPattern result, String name,
boolean anIsMeta, boolean anIsFullMatch, MatchStrategy aMatchStrategy) {
super(act, name, anIsMeta, anIsFullMatch, false, aMatchStrategy);
boolean anIsMeta, boolean anIncludeMetaKIs, MatchStrategy aMatchStrategy) {
super(act, name, anIsMeta, anIncludeMetaKIs, false, aMatchStrategy);
this.argument = argument;
this.result = result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -34,7 +35,7 @@ public void setUpServer() {
}

@Test
public void testAskAnswerReactWithGaps() throws IOException {
public void testAskAnswerReactWithGaps() throws IOException, InterruptedException {

// In this test there will be an Ask KB with an AskKI with 2 triplepatterns,
// an AnswerKB with a single AnswerKI that answers only the first triplepattern
Expand All @@ -46,6 +47,10 @@ public void testAskAnswerReactWithGaps() throws IOException {

URL url = new URL("http://localhost:" + PORT + "/rest");

// sync between threads to make sure the ask is not activated before the others
// are ready.
CountDownLatch KBReady = new CountDownLatch(2);

// activate the answer SC, KB, KI in a separate thread
var answeringSc = new AsyncTester(new Runnable() {
@Override
Expand All @@ -70,6 +75,8 @@ public void run() {
"Content-Type", "application/json", "Accept", "*/*"));
registerAnswerKi.expectStatus(200);

KBReady.countDown();

// get the handle for the answerKB to see if there are requests to be handled
var test = new HttpTester(new URL(url.toString() + "/sc/handle"), "GET", null, Map
.of("Knowledge-Base-Id", answerKBId, "Content-Type", "application/json", "Accept", "*/*"));
Expand Down Expand Up @@ -128,6 +135,8 @@ public void run() {
"Content-Type", "application/json", "Accept", "*/*"));
registerReactKi.expectStatus(200);

KBReady.countDown();

System.out.println("Getting the handle for the reactKBId");
// get the handle for the reactKB to see if there are requests to be handled =>
// NOTE: it should never exit/return this handle for this test
Expand Down Expand Up @@ -161,6 +170,8 @@ public void run() {
});
reactingSc.start();

KBReady.await();

// register the AskKB
HttpTester registerKb = new HttpTester(new URL(url + "/sc"), "POST",
"{\"knowledgeBaseId\": \"https://www.tno.nl/example/relationAsker\", \"knowledgeBaseName\": \"RelationAsker\", \"knowledgeBaseDescription\": \"A KB that asks for relations between people\", \"reasonerEnabled\" : true}",
Expand Down

0 comments on commit cc8545d

Please sign in to comment.