Skip to content

Commit

Permalink
Added tests for the DNB scenario with custom max match and context size.
Browse files Browse the repository at this point in the history
Change-Id: Ie0a78c79d6f4128c400230f64929c062ffa400f5
  • Loading branch information
margaretha committed May 23, 2024
1 parent 1668d87 commit 46e2c95
Show file tree
Hide file tree
Showing 8 changed files with 599 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ src\main\resources\Kustvakt.conf
/test-config-icc.xml
/data/
/old-jars/
/data-backup
/data-backup
/notes
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# version 0.73.2-SNAPSHOT

- Added tests for the DNB scenario with custom max match
and context size. (#745)

# version 0.73.1

- Fixed jakarta validation error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.util.Set;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.ids_mannheim.korap.util.KrillProperties;
import de.ids_mannheim.korap.utils.TimeUtils;
import lombok.Getter;
Expand All @@ -41,6 +44,9 @@ public class KustvaktConfiguration {
public static final Map<String, Object> KUSTVAKT_USER = new HashMap<>();
public static final String DATA_FOLDER = "data";

public final static Logger log = LoggerFactory
.getLogger(KustvaktConfiguration.class);

private String vcInCaching;

private String indexDir;
Expand Down Expand Up @@ -139,6 +145,7 @@ public void loadBasicProperties (Properties properties) {
*/
protected void load (Properties properties) throws Exception {
loadBasicProperties(properties);
loadKrillProperties(properties);

apiWelcomeMessage = properties.getProperty("api.welcome.message",
"Welcome to KorAP API!");
Expand Down Expand Up @@ -215,6 +222,26 @@ protected void load (Properties properties) throws Exception {
networkEndpointURL = properties.getProperty("network.endpoint.url", "");
}

private void loadKrillProperties (Properties properties) {
try {
String maxTokenMatch = properties.getProperty("krill.match.max.token");
if (maxTokenMatch != null) {
KrillProperties.maxTokenMatchSize = Integer.parseInt(maxTokenMatch);
}

String maxTokenContext = properties
.getProperty("krill.context.max.token");
if (maxTokenContext != null) {
KrillProperties.maxTokenContextSize = Integer
.parseInt(maxTokenContext);
}
}
catch (NumberFormatException e) {
log.error("A Krill property expects numerical values: "
+ e.getMessage());
};
}

@Deprecated
public void readPipesFile (String filename) throws IOException {
File file = new File(filename);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SearchKrill {
private static final boolean DEBUG = false;

public static KrillIndex index;

/**
* Constructor
*/
Expand All @@ -60,7 +60,7 @@ public SearchKrill (String path) {
jlog.error("Unable to loadSubTypes index:" + e.getMessage());
};
};

public KrillIndex getIndex () {
return index;
};
Expand Down
78 changes: 78 additions & 0 deletions src/test/java/de/ids_mannheim/korap/scenario/DNBTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package de.ids_mannheim.korap.scenario;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.ContextConfiguration;

import com.fasterxml.jackson.databind.JsonNode;

import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.util.KrillProperties;
import de.ids_mannheim.korap.utils.JsonUtils;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;

@ContextConfiguration("classpath:test-config-dnb.xml")
public class DNBTest extends SpringJerseyTest {

public final static String API_VERSION = "v1.0";

private JsonNode sendQuery (String query) throws KustvaktException {
Response r = target().path(API_VERSION).path("search")
.queryParam("q", query).queryParam("ql", "poliqarp")
.queryParam("show-tokens", true).request().get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
String entity = r.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);

return node;

}

@AfterAll
public static void resetKrillProperties() {
KrillProperties.loadProperties("kustvakt-test.conf");
}

@Test
public void testTokenMatchSize () throws KustvaktException {
assertEquals(1, KrillProperties.maxTokenMatchSize);
assertEquals(25, KrillProperties.maxTokenContextSize);

JsonNode node = sendQuery("[orth=das]");
assertEquals(KrillProperties.maxTokenMatchSize,
node.at("/matches/0/tokens/match").size());

node = sendQuery("[orth=das][orth=Glück]");
assertEquals(KrillProperties.maxTokenMatchSize,
node.at("/matches/0/tokens/match").size());
}

@Test
public void testTokenContextMatchSize () throws KustvaktException {
Response r = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=das][orth=Glück]")
.queryParam("ql", "poliqarp").queryParam("show-tokens", true)
.queryParam("context", "30-token,30-token").request().get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
String entity = r.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);

assertEquals(KrillProperties.maxTokenContextSize,
node.at("/meta/context/left/1").asInt());
assertEquals(KrillProperties.maxTokenContextSize,
node.at("/meta/context/right/1").asInt());

assertEquals(KrillProperties.maxTokenContextSize,
node.at("/matches/0/tokens/left").size());

// There is a bug in Krill (https://github.com/KorAP/Krill/issues/141)
// So the following test fails
// assertEquals(KrillProperties.maxTokenContextSize,
// node.at("/matches/0/tokens/right").size());
}

}
126 changes: 126 additions & 0 deletions src/test/resources/kustvakt-dnb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Krill settings
#
# A sample configuration for the DNB instance

krill.match.max.token=1
krill.context.max.token=25

krill.indexDir = sample-index

krill.index.commit.count = 134217000
krill.index.commit.log = log/krill.commit.log
krill.index.commit.auto = 500
krill.index.relations.max = 100
# Directory path of virtual corpora to cache
krill.namedVC = vc
krill.test = true

# LDAP configuration file
#
ldap.config = src/test/resources/test-ldap.conf

# Kustvakt versions
#
# multiple versions separated by space
current.api.version = v1.0
supported.api.version = v0.1 v1.0

# Server
#
server.port=8089
server.host=localhost

# Mail settings
#
mail.enabled = false
mail.receiver = test@localhost
mail.sender = [email protected]
mail.address.retrieval = test

# Mail.templates
#
template.group.invitation = notification.vm

# Default foundries for specific layers (optional)
#
default.foundry.partOfSpeech = tt
default.foundry.lemma = tt
default.foundry.orthography = opennlp
default.foundry.dependency = malt
default.foundry.constituent = corenlp
default.foundry.morphology = marmot
default.foundry.surface = base

# Delete configuration (default hard)
#
# delete.auto.group = hard
delete.group = soft
delete.group.member = soft

# Virtual corpus and queries
max.user.persistent.queries = 5

# Availability regex only support |
# It should be removed/commented when the data doesn't contain availability field.
#
availability.regex.free = CC-BY.*
availability.regex.public = ACA.*|QAO-NC
availability.regex.all = QAO.*


# Define resource filters for search and match info API
# AuthenticationFilter activates authentication using OAuth2 tokens
# DemoUserFilter allows access to API without login
#
# Default values: AuthenticationFilter,DemoUserFilter
#
search.resource.filters=AuthenticationFilter,DemoUserFilter


# options referring to the security module!

# OAuth
# (see de.ids_mannheim.korap.constant.AuthenticationMethod for possible
# oauth.password.authentication values)
#
oauth2.password.authentication = TEST
oauth2.native.client.host = korap.ids-mannheim.de
oauth2.max.attempts = 2
# expiry in seconds (S), minutes (M), hours (H), days (D)
oauth2.access.token.expiry = 3M
oauth2.refresh.token.expiry = 90D
oauth2.authorization.code.expiry = 10M
# -- scopes separated by space
oauth2.default.scopes = search match_info
oauth2.client.credentials.scopes = client_info

oauth2.initial.super.client=true


# see SecureRandom Number Generation Algorithms
# optional
security.secure.random.algorithm=SHA1PRNG

# see MessageDigest Algorithms
# default MD5
security.md.algoritm = SHA-256

# secure hash support: BCRYPT
security.secure.hash.algorithm=BCRYPT
security.encryption.loadFactor = 10

# DEPRECATED
# JWT
security.jwt.issuer=https://korap.ids-mannheim.de
security.sharedSecret=this-is-shared-secret-code-for-JWT-Signing.It-must-contains-minimum-256-bits

# token expiration time
security.longTokenTTL = 1D
security.tokenTTL = 2S
security.shortTokenTTL = 1S

# Session authentication
security.idleTimeoutDuration = 25M
security.multipleLogIn = true
security.loginAttemptNum = 3
security.authAttemptTTL = 45M
3 changes: 3 additions & 0 deletions src/test/resources/kustvakt-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ krill.index.relations.max = 100
krill.namedVC = vc
krill.test = true

krill.match.max.token=50
krill.context.max.token=60

# LDAP configuration file
#
ldap.config = src/test/resources/test-ldap.conf
Expand Down
Loading

0 comments on commit 46e2c95

Please sign in to comment.