Skip to content

Commit

Permalink
fix junti test passed; fixed forced bindings for multiple updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lroffia committed Dec 6, 2024
1 parent 1a98a77 commit 252c03a
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public SPARQL11SEProperties(URI uri, String[] args) throws SEPAPropertiesExcepti
Logging.logger.trace("Argument " + args[i]);
String[] params = args[i].split("=");
if (params.length == 2) {
setParameter(params[0], params[1]);
setSeParameter(params[0], params[1]);
}
}
}
Expand Down
35 changes: 25 additions & 10 deletions client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
}}
* </pre>
*/
@SuppressWarnings("JavadocLinkAsPlainText")
public class JSAP extends SPARQL11SEProperties {
private static final Set<String> numbersOrBoolean = new HashSet<>();
private final PrefixMappingMem prefixes;
Expand Down Expand Up @@ -451,6 +450,12 @@ public boolean reconnect() {
/*
* UPDATE
*/
public String getUpdateHost() {
String ret = sparql11protocol.getHost();
if (ret == null) ret = host;
return ret;
}

public String getSPARQLUpdate(String id) {
return (updates.get(id) == null ? null : updates.get(id).sparql);
}
Expand Down Expand Up @@ -596,6 +601,12 @@ public void setUsingGraphURI(String id, Set<String> graph) {
/*
* QUERY
*/
public String getQueryHost() {
String ret = sparql11protocol.getHost();
if (ret == null) ret = host;
return ret;
}

public String getSPARQLQuery(String id) {
return (queries.get(id) == null ? null : queries.get(id).sparql);
}
Expand Down Expand Up @@ -738,7 +749,12 @@ public void setDefaultGraphURI(String id, Set<String> graph) {
/*
* SUBSCRIBE
*/

public String getSubscribeHost() {
String ret = sparql11seprotocol.getHost();
if (ret == null) ret = host;
return ret;
}

public String getSubscribeHost(String id) {
String ret=null;
try {
Expand Down Expand Up @@ -1030,12 +1046,13 @@ public String addPrefixesAndReplaceBindings(String sparql, Bindings bindings) th
UpdateRequest request = UpdateFactory.create();
request.setPrefixMapping(prefixes);
UpdateFactory.parse(request, replaceBindings(sparql, bindings));
IndentedWriter writer = new IndentedLineBuffer();
UpdateWriterVisitor visitor = new UpdateWriterVisitor(writer, new SerializationContext());


for (Update upd : request.getOperations()) {
IndentedWriter writer = new IndentedLineBuffer();
UpdateWriterVisitor visitor = new UpdateWriterVisitor(writer, new SerializationContext());
if (!sb.toString().isEmpty()) sb.append(";");

else sb.append(prologue);

if (upd instanceof UpdateDataDelete)
visitor.visit((UpdateDataDelete) upd);
else if (upd instanceof UpdateDataInsert)
Expand All @@ -1061,13 +1078,11 @@ else if (upd instanceof UpdateCreate)
else if (upd instanceof UpdateModify)
visitor.visit((UpdateModify) upd);

if (upd instanceof UpdateModify || upd instanceof UpdateAdd || upd instanceof UpdateDataDelete || upd instanceof UpdateDataInsert
|| upd instanceof UpdateDeleteWhere)
sb.append(prologue);

sb.append(writer);
}



} catch (QueryParseException ex) {
sb.append(prologue).append(replaceBindings(sparql, bindings));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
import it.unibo.arces.wot.sepa.pattern.JSAP;

import java.io.Closeable;
import java.io.File;
//import java.io.File;
import java.io.IOException;
import java.net.URI;
//import java.net.URI;
import java.util.UUID;

public class ConfigurationProvider implements Closeable {
private final JSAP appProfile;
private String prefixes = "";
private final String jsapPath;
//private final String jsapPath;

public long TIMEOUT;
public long NRETRY;
Expand All @@ -34,25 +34,26 @@ public class ConfigurationProvider implements Closeable {
public ConfigurationProvider() throws SEPAPropertiesException, SEPASecurityException {
String jsapFileName = "sepatest.jsap";

if (System.getProperty("testConfiguration") != null) {
jsapFileName = System.getProperty("testConfiguration");
Logging.logger.debug("JSAP from property testConfiguration: " + jsapFileName);
} else if (System.getProperty("secure") != null) {
jsapFileName = "sepatest-secure.jsap";
Logging.logger.debug("JSAP secure default: " + jsapFileName);
}

jsapPath = getClass().getClassLoader().getResource(jsapFileName).getPath();
File f = new File(jsapPath);
if (!f.exists()) {
Logging.logger.error("File not found: " + jsapPath);
throw new SEPAPropertiesException("File not found: " + jsapPath);
}

Logging.logger.debug("Loading JSAP from: " + f.getPath());
// if (System.getProperty("testConfiguration") != null) {
// jsapFileName = System.getProperty("testConfiguration");
// Logging.logger.debug("JSAP from property testConfiguration: " + jsapFileName);
// } else if (System.getProperty("secure") != null) {
// jsapFileName = "sepatest-secure.jsap";
// Logging.logger.debug("JSAP secure default: " + jsapFileName);
// }
//
// jsapPath = getClass().getClassLoader().getResource(jsapFileName).getPath();
// File f = new File(jsapPath);
// if (!f.exists()) {
// Logging.logger.error("File not found: " + jsapPath);
// throw new SEPAPropertiesException("File not found: " + jsapPath);
// }
//
// Logging.logger.debug("Loading JSAP from: " + f.getPath());

try {
appProfile = new JSAP(URI.create(f.getPath()));
// appProfile = new JSAP(URI.create(f.getPath()));
appProfile = new JSAP(jsapFileName);
} catch (SEPAPropertiesException e) {
Logging.logger.error(e.getMessage());
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Publisher(ConfigurationProvider provider, String id, long n)

running = new AtomicLong(n);

this.setName("Publisher-" + id + "-" + this.getId());
this.setName("Publisher-" + id + "-" + this.threadId());
this.provider = provider;

client = new SPARQL11Protocol(provider.getClientSecurityManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Subscriber extends Thread implements Closeable, ISubscriptionHandle
public Subscriber(ConfigurationProvider provider, String id, ISubscriptionHandler sync)
throws SEPAProtocolException, SEPASecurityException, SEPAPropertiesException {

this.setName("Subscriber-" + id + "-" + this.getId());
this.setName("Subscriber-" + id + "-" + this.threadId());
this.provider = provider;
this.id = id;
this.handler = sync;
Expand Down
8 changes: 4 additions & 4 deletions client-api/src/test/java/it/unibo/arces/wot/sepa/Sync.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public synchronized void waitSubscribes(int total) {
synchronized (subscribesMutex) {
while (subscribes < total) {
try {
Logging.logger.trace("Thread id "+Thread.currentThread().getId()+ " waitSubscribes");
Logging.logger.trace("Thread id "+Thread.currentThread().threadId()+ " waitSubscribes");
subscribesMutex.wait();
Logging.logger.trace("Thread id "+Thread.currentThread().getId()+ " awaken from waitSubscribes");
Logging.logger.trace("Thread id "+Thread.currentThread().threadId()+ " awaken from waitSubscribes");
} catch (InterruptedException e) {
throw new RuntimeException(e.getCause());
}
Expand Down Expand Up @@ -88,9 +88,9 @@ public synchronized void waitEvents(int total) {
synchronized (eventsMutex) {
while (events < total) {
try {
Logging.logger.trace("Thread id "+Thread.currentThread().getId()+ " waitEvents");
Logging.logger.trace("Thread id "+Thread.currentThread().threadId()+ " waitEvents");
eventsMutex.wait();
Logging.logger.trace("Thread id "+Thread.currentThread().getId()+ " awaken from waitEvents");
Logging.logger.trace("Thread id "+Thread.currentThread().threadId()+ " awaken from waitEvents");
} catch (InterruptedException e) {
throw new RuntimeException(e.getCause());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public static void end() {
public void beginTest() throws SEPAProtocolException, SEPASecurityException, SEPAPropertiesException, SEPABindingsException, InterruptedException, IOException {
Thread.sleep(ConfigurationProvider.SLEEP);

assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+"Unsubscribes: "+sync.getUnsubscribes());

sync.reset();

assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+" == Unsubscribes: "+sync.getUnsubscribes());

Producer deleteAll = new Producer(provider.getJsap(), "DELETE_ALL");
deleteAll.update();
deleteAll.close();
Expand All @@ -53,7 +53,7 @@ public void beginTest() throws SEPAProtocolException, SEPASecurityException, SEP

@AfterEach
public void afterTest() throws IOException, InterruptedException, SEPASecurityException, SEPAPropertiesException, SEPAProtocolException {
assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+"Unsubscribes: "+sync.getUnsubscribes());
assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+" == Unsubscribes: "+sync.getUnsubscribes());
}

@RepeatedTest(ConfigurationProvider.REPEATED_TEST)
Expand Down Expand Up @@ -84,7 +84,7 @@ public void aggregationX10() throws InterruptedException, SEPASecurityException,
randomAggregator.syncUnsubscribe(provider.TIMEOUT, provider.NRETRY);
consumerRandom1.syncUnsubscribe(provider.TIMEOUT, provider.NRETRY);

assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+"Unsubscribes: "+sync.getUnsubscribes());
assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+" == Unsubscribes: "+sync.getUnsubscribes());

randomAggregator.close();
consumerRandom1.close();
Expand Down Expand Up @@ -120,7 +120,7 @@ public void aggregationX100() throws InterruptedException, SEPASecurityException
randomAggregator.syncUnsubscribe(provider.TIMEOUT, provider.NRETRY);
consumerRandom1.syncUnsubscribe(provider.TIMEOUT, provider.NRETRY);

assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+"Unsubscribes: "+sync.getUnsubscribes());
assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+" == Unsubscribes: "+sync.getUnsubscribes());

randomAggregator.close();
consumerRandom1.close();
Expand Down
4 changes: 2 additions & 2 deletions client-api/src/test/resources/sepatest.jsap
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"protocol": "http",
"port": 8000,
"query": {
"path": "/sparql",
"path": "/query",
"method": "POST",
"format": "JSON"
},
"update": {
"path": "/sparql",
"path": "/update",
"method": "POST",
"format": "JSON"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public int getWsShutdownTimeout(){
public String getSSLCertificate() {
if (!isSecure())
return "Security off";
return jwt.getParsedX509CertChain().get(0).getIssuerDN().getName() + " "
return jwt.getParsedX509CertChain().get(0).getSubjectX500Principal().getName() + " "
+ jwt.getParsedX509CertChain().get(0).getNotAfter().toString();
}

Expand Down
21 changes: 10 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.unibo.arces.wot</groupId>
<artifactId>sepa</artifactId>
Expand Down Expand Up @@ -68,9 +68,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<version>3.9.0</version>
<configuration>
<release>11</release>
<release>23</release>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -138,7 +138,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
Expand Down Expand Up @@ -202,16 +202,15 @@
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.40</version>
</dependency>
<!--
https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<version>5.11.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
Expand Down

0 comments on commit 252c03a

Please sign in to comment.