Skip to content

Commit

Permalink
cleanup/fix settings + AutomataLib adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
mtf90 committed Dec 22, 2024
1 parent ca55b47 commit c46cefd
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 51 deletions.
7 changes: 7 additions & 0 deletions commons/settings/learnlib.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#This file is explicitly not part of test/resources to check whether the local file reader works correctly
learnlib.parallel.batch_size.dynamic=1
learnlib.parallel.batch_size.static=2
learnlib.parallel.pool_policy=CACHED
learnlib.parallel.pool_size=3
automatalib.word.delim.right=delim_right
automatalib.word.delim.left=delim_left_override
5 changes: 3 additions & 2 deletions commons/settings/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ limitations under the License.
<artifactId>learnlib-settings</artifactId>

<name>LearnLib :: Commons :: Settings</name>
<description>A collection of utility methods to parse LearnLib specific settings</description>
<description>A collection of utility methods to parse LearnLib specific settings.</description>

<dependencies>
<!-- internal -->
Expand All @@ -40,8 +40,9 @@ limitations under the License.
<!-- external -->
<dependency>
<groupId>net.automatalib</groupId>
<artifactId>automata-api</artifactId>
<artifactId>automata-commons-settings</artifactId>
</dependency>

<dependency>
<groupId>net.automatalib</groupId>
<artifactId>automata-commons-util</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Locale;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.function.Function;

import de.learnlib.logging.Category;
Expand All @@ -34,7 +35,7 @@ public final class LearnLibSettings {
private final Properties properties;

private LearnLibSettings() {
properties = SettingsSource.readSettings(SettingsSource.class);
properties = SettingsSource.readSettings(ServiceLoader.load(LearnLibSettingsSource.class));
}

public static LearnLibSettings getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@

import net.automatalib.common.util.setting.SettingsSource;

public interface LearnLibSettingsSource extends SettingsSource {

}
public interface LearnLibSettingsSource extends SettingsSource {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
*/
package de.learnlib.setting.sources;

import net.automatalib.AutomataLibSettingsSource;
import net.automatalib.common.setting.AutomataLibSettingsSource;
import net.automatalib.common.util.setting.LocalFileSource;
import net.automatalib.common.util.setting.SettingsSource;
import org.kohsuke.MetaInfServices;

@MetaInfServices(SettingsSource.class)
@MetaInfServices(AutomataLibSettingsSource.class)
public class LearnLibLocalPropertiesAutomataLibSettingsSource extends LocalFileSource
implements AutomataLibSettingsSource {

private static final int PRIORITY_DECREASE = 10;

public LearnLibLocalPropertiesAutomataLibSettingsSource() {
super("learnlib.properties");
super("./learnlib.properties");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

import de.learnlib.setting.LearnLibSettingsSource;
import net.automatalib.common.util.setting.LocalFileSource;
import net.automatalib.common.util.setting.SettingsSource;
import org.kohsuke.MetaInfServices;

@MetaInfServices(SettingsSource.class)
@MetaInfServices(LearnLibSettingsSource.class)
public class LearnLibLocalPropertiesSource extends LocalFileSource implements LearnLibSettingsSource {

public LearnLibLocalPropertiesSource() {
super("learnlib.properties");
super("./learnlib.properties");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@
*/
package de.learnlib.setting.sources;

import net.automatalib.AutomataLibSettingsSource;
import net.automatalib.common.setting.AutomataLibSettingsSource;
import net.automatalib.common.util.setting.AbstractClassPathFileSource;
import net.automatalib.common.util.setting.SettingsSource;
import org.kohsuke.MetaInfServices;

@MetaInfServices(SettingsSource.class)
@MetaInfServices(AutomataLibSettingsSource.class)
public class LearnLibPropertiesAutomataLibSettingsSource extends AbstractClassPathFileSource
implements AutomataLibSettingsSource {

private static final int DEFAULT_PRIORITY = -10;
private static final int PRIORITY_DECREASE = 10;

public LearnLibPropertiesAutomataLibSettingsSource() {
super("learnlib.properties");
}

@Override
public int getPriority() {
return DEFAULT_PRIORITY;
return super.getPriority() - PRIORITY_DECREASE; // bump prio down a bit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

import de.learnlib.setting.LearnLibSettingsSource;
import net.automatalib.common.util.setting.AbstractClassPathFileSource;
import net.automatalib.common.util.setting.SettingsSource;
import org.kohsuke.MetaInfServices;

@MetaInfServices(SettingsSource.class)
@MetaInfServices(LearnLibSettingsSource.class)
public class LearnLibPropertiesSource extends AbstractClassPathFileSource implements LearnLibSettingsSource {

public LearnLibPropertiesSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
*/
package de.learnlib.setting.sources;

import net.automatalib.AutomataLibSettingsSource;
import net.automatalib.common.setting.AutomataLibSettingsSource;
import net.automatalib.common.util.setting.AbstractSystemPropertiesSource;
import net.automatalib.common.util.setting.SettingsSource;
import org.kohsuke.MetaInfServices;

@MetaInfServices(SettingsSource.class)
@MetaInfServices(AutomataLibSettingsSource.class)
public class LearnLibSystemPropertiesAutomataLibSettingsSource extends AbstractSystemPropertiesSource
implements AutomataLibSettingsSource {}
implements AutomataLibSettingsSource {

private static final int PRIORITY_DECREASE = 10;

@Override
public int getPriority() {
return super.getPriority() - PRIORITY_DECREASE; // bump prio down a bit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

import de.learnlib.setting.LearnLibSettingsSource;
import net.automatalib.common.util.setting.AbstractSystemPropertiesSource;
import net.automatalib.common.util.setting.SettingsSource;
import org.kohsuke.MetaInfServices;

@MetaInfServices(SettingsSource.class)
@MetaInfServices(LearnLibSettingsSource.class)
public class LearnLibSystemPropertiesSource extends AbstractSystemPropertiesSource implements LearnLibSettingsSource {}
10 changes: 7 additions & 3 deletions commons/settings/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

import de.learnlib.setting.LearnLibSettingsSource;
import de.learnlib.setting.sources.LearnLibLocalPropertiesAutomataLibSettingsSource;
import de.learnlib.setting.sources.LearnLibLocalPropertiesSource;
import de.learnlib.setting.sources.LearnLibPropertiesAutomataLibSettingsSource;
import de.learnlib.setting.sources.LearnLibPropertiesSource;
import de.learnlib.setting.sources.LearnLibSystemPropertiesAutomataLibSettingsSource;
import de.learnlib.setting.sources.LearnLibSystemPropertiesSource;
import net.automatalib.common.util.setting.SettingsSource;
import net.automatalib.common.setting.AutomataLibSettingsSource;

/**
* This module provides a collection of utility methods to parse LearnLib specific settings.
Expand All @@ -37,8 +38,8 @@
open module de.learnlib.setting {

requires de.learnlib.api;
requires net.automatalib.common.setting;
requires net.automatalib.common.util;
requires net.automatalib.api;
requires org.slf4j;

// make non-static once https://github.com/typetools/checker-framework/issues/4559 is implemented
Expand All @@ -48,5 +49,8 @@
exports de.learnlib.setting;
exports de.learnlib.setting.sources;

provides SettingsSource with LearnLibLocalPropertiesAutomataLibSettingsSource, LearnLibPropertiesAutomataLibSettingsSource, LearnLibSystemPropertiesAutomataLibSettingsSource, LearnLibLocalPropertiesSource, LearnLibPropertiesSource, LearnLibSystemPropertiesSource;
uses LearnLibSettingsSource;

provides LearnLibSettingsSource with LearnLibLocalPropertiesSource, LearnLibPropertiesSource, LearnLibSystemPropertiesSource;
provides AutomataLibSettingsSource with LearnLibLocalPropertiesAutomataLibSettingsSource, LearnLibPropertiesAutomataLibSettingsSource, LearnLibSystemPropertiesAutomataLibSettingsSource;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,44 @@
*/
package de.learnlib.setting;

import java.io.File;
import java.net.URL;

import net.automatalib.common.setting.AutomataLibProperty;
import net.automatalib.common.setting.AutomataLibSettings;
import org.testng.Assert;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class LearnLibSettingsTest {

@BeforeSuite
public void setUp() {
final URL resource = LearnLibSettingsTest.class.getResource("/learnlib.properties");
assert resource != null;
final File properties = new File(resource.getFile());
System.setProperty("learnlib.properties", properties.getAbsolutePath());
}

@Test
public void testProperties() {
public void testLearnLibProperties() {
LearnLibSettings settings = LearnLibSettings.getInstance();

for (LearnLibProperty p : LearnLibProperty.values()) {
switch (p) {
case PARALLEL_BATCH_SIZE_DYNAMIC:
Assert.assertEquals(1, settings.getInt(LearnLibProperty.PARALLEL_BATCH_SIZE_DYNAMIC, 0));
Assert.assertEquals(settings.getInt(LearnLibProperty.PARALLEL_BATCH_SIZE_DYNAMIC, 0), 1);
break;
case PARALLEL_BATCH_SIZE_STATIC:
Assert.assertEquals(2, settings.getInt(LearnLibProperty.PARALLEL_BATCH_SIZE_STATIC, 0));
Assert.assertEquals(settings.getInt(LearnLibProperty.PARALLEL_BATCH_SIZE_STATIC, 0), 2);
break;
case PARALLEL_POOL_POLICY:
Assert.assertEquals("CACHED", settings.getProperty(LearnLibProperty.PARALLEL_POOL_POLICY));
Assert.assertEquals(settings.getProperty(LearnLibProperty.PARALLEL_POOL_POLICY), "CACHED");
break;
case PARALLEL_POOL_SIZE:
Assert.assertEquals(3, settings.getInt(LearnLibProperty.PARALLEL_POOL_SIZE, 0));
Assert.assertEquals(settings.getInt(LearnLibProperty.PARALLEL_POOL_SIZE, 0), 3);
break;
default:
throw new IllegalStateException("Unhandled property " + p);
}
}
}

@Test
public void testAutomataLibProperties() {
AutomataLibSettings settings = AutomataLibSettings.getInstance();

// LearnLib should load properties for AutomataLib from learnlib.properties files but prefer automatalib.properties
Assert.assertEquals(settings.getProperty(AutomataLibProperty.WORD_EMPTY_REP), "empty_rep");
Assert.assertEquals(settings.getProperty(AutomataLibProperty.WORD_DELIM_RIGHT), "delim_right");
Assert.assertEquals(settings.getProperty(AutomataLibProperty.WORD_DELIM_LEFT), "delim_left_override");
}
}
2 changes: 2 additions & 0 deletions commons/settings/src/test/resources/automatalib.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
automatalib.word.empty=empty_rep
automatalib.word.delim.left=delim_left
4 changes: 0 additions & 4 deletions commons/settings/src/test/resources/learnlib.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public abstract class AbstractStaticBatchProcessor<Q, P extends BatchProcessor<Q

MIN_BATCH_SIZE = settings.getInt(LearnLibProperty.PARALLEL_BATCH_SIZE_STATIC, DEFAULT_MIN_BATCH_SIZE);
NUM_INSTANCES = settings.getInt(LearnLibProperty.PARALLEL_POOL_SIZE, numCores);
POOL_POLICY = settings.getEnumValue(LearnLibProperty.PARALLEL_POOL_SIZE, PoolPolicy.class, PoolPolicy.CACHED);
POOL_POLICY = settings.getEnumValue(LearnLibProperty.PARALLEL_POOL_POLICY, PoolPolicy.class, PoolPolicy.CACHED);
}

private final @NonNegative int minBatchSize;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Copyright (C) 2013-2024 TU Dortmund University
* This file is part of LearnLib, http://www.learnlib.de/.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.learnlib.oracle.parallelism;

import org.testng.Assert;
import org.testng.annotations.Test;

public class SettingsTest {

@Test
public void testDynamicProcessor() {
// best-case would be to test a non-default value but that somehow slows down the tests a lot
Assert.assertEquals(AbstractDynamicBatchProcessor.BATCH_SIZE, 1);
Assert.assertEquals(AbstractDynamicBatchProcessor.POOL_POLICY.name(), "FIXED");
Assert.assertEquals(AbstractDynamicBatchProcessor.POOL_SIZE, 5);
}

@Test
public void testStaticProcessor() {
Assert.assertEquals(AbstractStaticBatchProcessor.MIN_BATCH_SIZE, 4);
Assert.assertEquals(AbstractStaticBatchProcessor.POOL_POLICY.name(), "FIXED");
Assert.assertEquals(AbstractStaticBatchProcessor.NUM_INSTANCES, 5);
}
}
4 changes: 4 additions & 0 deletions oracles/parallelism/src/test/resources/learnlib.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
learnlib.parallel.batch_size.dynamic=1
learnlib.parallel.batch_size.static=4
learnlib.parallel.pool_policy=FIXED
learnlib.parallel.pool_size=5

0 comments on commit c46cefd

Please sign in to comment.