Skip to content

Commit

Permalink
Replace xstream with fury (#127)
Browse files Browse the repository at this point in the history
* initial fury transition

* switch to fury nightly

* use new module names

* switch to stable release

* remove rebase artifact

* bump version
  • Loading branch information
mtf90 authored Jun 13, 2024
1 parent 5f811f0 commit f4518a0
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 122 deletions.
26 changes: 0 additions & 26 deletions algorithms/active/lstar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,30 +140,4 @@ limitations under the License.
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>fix-xstream</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
@{argLine}
--add-reads=de.learnlib.algorithm.lstar=net.automatalib.util
--add-opens=java.base/java.util=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
22 changes: 0 additions & 22 deletions algorithms/active/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,4 @@ limitations under the License.
<module>ttt</module>
<module>ttt-vpa</module>
</modules>

<profiles>
<profile>
<id>fix-xstream</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} --add-opens=java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
13 changes: 6 additions & 7 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ limitations under the License.
<groupId>de.learnlib</groupId>
<artifactId>learnlib-statistics</artifactId>
</dependency>
<dependency>
<groupId>de.learnlib.testsupport</groupId>
<artifactId>learnlib-test-support</artifactId>
<scope>compile</scope>
<!-- Override! -->
</dependency>
<dependency>
<groupId>de.learnlib</groupId>
<artifactId>learnlib-ttt</artifactId>
Expand All @@ -127,11 +133,6 @@ limitations under the License.
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>

<dependency>
<groupId>net.automatalib</groupId>
<artifactId>automata-api</artifactId>
Expand Down Expand Up @@ -200,8 +201,6 @@ limitations under the License.
<java.awt.graphicsenv>com.github.caciocavallosilano.cacio.ctc.CTCGraphicsEnvironment</java.awt.graphicsenv>
<java.awt.headless>false</java.awt.headless>
</systemPropertyVariables>
<!-- append to existing argLine to nicely work together with jacoco plugin -->
<argLine>@{argLine} --add-opens=java.base/java.util=xstream</argLine>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package de.learnlib.example.resumable;

import java.nio.charset.StandardCharsets;
import java.util.Random;

import com.thoughtworks.xstream.XStream;
import de.learnlib.Resumable;
import de.learnlib.algorithm.lstar.dfa.ClassicLStarDFA;
import de.learnlib.filter.cache.dfa.DFACacheOracle;
Expand All @@ -29,6 +27,7 @@
import de.learnlib.oracle.equivalence.DFASimulatorEQOracle;
import de.learnlib.oracle.membership.DFASimulatorOracle;
import de.learnlib.query.DefaultQuery;
import de.learnlib.testsupport.ResumeUtils;
import net.automatalib.alphabet.Alphabet;
import net.automatalib.alphabet.impl.Alphabets;
import net.automatalib.alphabet.impl.GrowingMapAlphabet;
Expand All @@ -44,17 +43,13 @@ public final class ResumableExample {

private static final CompactDFA<Character> TARGET;
private static final Alphabet<Character> INITIAL_ALPHABET;
private static final XStream X_STREAM;

static {
final int seed = 42;
final int size = 100;

TARGET = RandomAutomata.randomDFA(new Random(seed), size, Alphabets.characters('a', 'd'));
INITIAL_ALPHABET = Alphabets.characters('a', 'b');

X_STREAM = new XStream();
X_STREAM.allowTypesByRegExp(new String[] {"net.automatalib.*", "de.learnlib.*"});
}

private ResumableExample() {
Expand All @@ -76,8 +71,8 @@ public static void main(String[] args) {
printStats(setup);

// serialize the current state of the learning setup which may be stored somewhere external
final byte[] learnerData = toBytes(setup.learner);
final byte[] cacheData = toBytes(setup.cache);
final byte[] learnerData = ResumeUtils.toBytes(setup.learner.suspend());
final byte[] cacheData = ResumeUtils.toBytes(setup.cache.suspend());

// continue exploring the previous snapshot with new input symbol 'c'
continueExploring(learnerData, cacheData, 'c');
Expand All @@ -92,10 +87,10 @@ private static void continueExploring(byte[] learnerData, byte[] cacheData, char
final Setup setup = new Setup();

// resume from previous states and add new symbol
setup.cache.resume(fromBytes(cacheData));
setup.cache.resume(ResumeUtils.fromBytes(cacheData));
setup.cache.addAlphabetSymbol(newSymbol);

setup.learner.resume(fromBytes(learnerData));
setup.learner.resume(ResumeUtils.fromBytes(learnerData));
setup.learner.addAlphabetSymbol(newSymbol);

// continue learning-loop
Expand All @@ -114,15 +109,6 @@ private static void printStats(Setup setup) {
System.out.println();
}

private static <T> byte[] toBytes(Resumable<T> resumable) {
return X_STREAM.toXML(resumable.suspend()).getBytes(StandardCharsets.UTF_8);
}

@SuppressWarnings("unchecked")
private static <T> T fromBytes(byte[] bytes) {
return (T) X_STREAM.fromXML(new String(bytes, StandardCharsets.UTF_8));
}

private static class Setup {

private final DFACounterOracle<Character> counter;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
requires de.learnlib.oracle.membership;
requires de.learnlib.oracle.parallelism;
requires de.learnlib.oracle.property;
requires de.learnlib.testsupport;
requires de.learnlib.testsupport.example;
requires net.automatalib.api;
requires net.automatalib.common.util;
Expand All @@ -49,7 +50,6 @@
requires net.automatalib.util;
requires net.automatalib.serialization.dot;
requires net.automatalib.visualization.dot;
requires xstream;

// make non-static once https://github.com/typetools/checker-framework/issues/4559 is implemented
requires static org.checkerframework.checker.qual;
Expand Down
28 changes: 0 additions & 28 deletions filters/cache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,4 @@ limitations under the License.
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>fix-xstream</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
@{argLine}
--add-opens=java.base/java.util=ALL-UNNAMED
--add-reads=de.learnlib.filter.cache=de.learnlib.filter.statistic
--add-reads=de.learnlib.filter.cache=de.learnlib.oracle.membership
--add-reads=de.learnlib.filter.cache=de.learnlib.oracle.parallelism
</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ limitations under the License.
<cacio.version>1.11.1</cacio.version>
<checkerframework.version>3.40.0</checkerframework.version>
<checkstyle.version>9.3</checkstyle.version>
<fury.version>0.5.1</fury.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
<logback.version>1.3.12</logback.version>
<metainf-services.version>1.11</metainf-services.version>
<mockito.version>5.6.0</mockito.version>
<slf4j.version>2.0.9</slf4j.version>
<testng.version>7.5.1</testng.version>
<xstream.version>1.4.20</xstream.version>
<testng.version>7.9.0</testng.version>

<!-- Javadoc links -->
<automatalib.apidocs>http://learnlib.github.io/automatalib/maven-site/${automatalib.version}/apidocs/</automatalib.apidocs>
Expand Down Expand Up @@ -615,9 +615,9 @@ limitations under the License.
</dependency>

<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>${xstream.version}</version>
<groupId>org.apache.fury</groupId>
<artifactId>fury-core</artifactId>
<version>${fury.version}</version>
</dependency>

<dependency>
Expand Down
9 changes: 4 additions & 5 deletions test-support/test-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
</dependency>

<!-- external -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>

<dependency>
<groupId>net.automatalib</groupId>
<artifactId>automata-api</artifactId>
Expand All @@ -66,6 +61,10 @@
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</dependency>
<dependency>
<groupId>org.apache.fury</groupId>
<artifactId>fury-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,33 @@
*/
package de.learnlib.testsupport;

import java.nio.charset.StandardCharsets;

import com.thoughtworks.xstream.XStream;
import de.learnlib.Resumable;
import org.apache.fury.Fury;
import org.apache.fury.logging.LoggerFactory;

/**
* Utility functions for {@link Resumable} features.
*/
public final class ResumeUtils {

private static final XStream X_STREAM;
private static final Fury FURY;

static {
X_STREAM = new XStream();
X_STREAM.allowTypesByRegExp(new String[] {"net.automatalib.*", "de.learnlib.*"});
LoggerFactory.useSlf4jLogging(true);
FURY = Fury.builder().withRefTracking(true).requireClassRegistration(false).build();
}

private ResumeUtils() {
// prevent instantiation
}

public static <T extends Object> byte[] toBytes(T state) {
return X_STREAM.toXML(state).getBytes(StandardCharsets.UTF_8);
return FURY.serialize(state);
}

@SuppressWarnings("unchecked")
public static <T> T fromBytes(byte[] bytes) {
return (T) X_STREAM.fromXML(new String(bytes, StandardCharsets.UTF_8));
return (T) FURY.deserialize(bytes);
}

}
2 changes: 1 addition & 1 deletion test-support/test-support/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
requires net.automatalib.common.util;
requires net.automatalib.core;
requires net.automatalib.util;
requires org.apache.fury.core;
requires org.mockito;
requires org.testng;
requires xstream;

// make non-static once https://github.com/typetools/checker-framework/issues/4559 is implemented
requires static org.checkerframework.checker.qual;
Expand Down

0 comments on commit f4518a0

Please sign in to comment.