Skip to content

Commit

Permalink
OptimisationService
Browse files Browse the repository at this point in the history
  • Loading branch information
apete committed Sep 20, 2024
1 parent e52116e commit a8a43d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
2 changes: 2 additions & 0 deletions ojAlgo Functionality Tests.launch
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<mapAttribute key="org.eclipse.debug.core.environmentVariables"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
<listEntry value="org.eclipse.eclemma.ui.launchGroup.coverage"/>
Expand All @@ -30,4 +31,5 @@
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="ojAlgo"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/>
</launchConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public abstract class OptimisationService {

public static final class Integration extends ExpressionsBasedModel.Integration<OptimisationService.Solver> {

private static final String PATH_ENVIRONMENT = "/optimisation/v01/environment";
private static final String PATH_TEST = "/optimisation/v01/test";

private Boolean myCapable = null;
Expand All @@ -56,28 +57,38 @@ public static final class Integration extends ExpressionsBasedModel.Integration<
myHost = host;
}

@Override
public OptimisationService.Solver build(final ExpressionsBasedModel model) {
return new OptimisationService.Solver(model, myHost);
}

public String getEnvironment() {
return ServiceClient.get(myHost + PATH_ENVIRONMENT).getBody();
}

@Override
public boolean isCapable(final ExpressionsBasedModel model) {

if (myCapable == null) {
Response<String> response = ServiceClient.get(myHost + PATH_TEST);
if (response.isResponseOK() && response.getBody().contains("VALID")) {
myCapable = Boolean.TRUE;
} else {
BasicLogger.error("Calling {} failed!", myHost + PATH_TEST);
myCapable = Boolean.FALSE;
}
myCapable = this.test();
}

return myCapable.booleanValue();
return Boolean.TRUE.equals(myCapable);
}

public Boolean test() {
Response<String> response = ServiceClient.get(myHost + PATH_TEST);
if (response.isResponseOK() && response.getBody().contains("VALID")) {
return Boolean.TRUE;
} else {
BasicLogger.error("Calling {} failed!", myHost + PATH_TEST);
return Boolean.FALSE;
}
}

}

public static final class Solver implements Optimisation.Solver {
static final class Solver implements Optimisation.Solver {

private static final String PATH_MAXIMISE = "/optimisation/v01/maximise";
private static final String PATH_MINIMISE = "/optimisation/v01/minimise";
Expand All @@ -93,6 +104,7 @@ public static final class Solver implements Optimisation.Solver {
myHost = host;
}

@Override
public Result solve(final Result kickStarter) {

InMemoryFile file = new InMemoryFile();
Expand All @@ -114,5 +126,4 @@ public Result solve(final Result kickStarter) {
public static OptimisationService.Integration newIntegration(final String host) {
return new Integration(host);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
import org.junit.jupiter.api.Test;
import org.ojalgo.TestUtils;
import org.ojalgo.netio.BasicLogger;
import org.ojalgo.netio.ServiceClient;
import org.ojalgo.netio.ServiceClient.Response;
import org.ojalgo.optimisation.ExpressionsBasedModel;
import org.ojalgo.optimisation.Optimisation.Result;

@Tag("network")
public class OptimisationServiceTest {

private static final String PATH_ENVIRONMENT = "/optimisation/v01/environment";
private static final String PATH_TEST = "/optimisation/v01/test";
private static final String HOST = "http://13.60.238.124:8080";
// private static final String HOST = "http://localhost:8080";
// private static final String HOST = "http://test-service.optimatika.se:8080";
Expand All @@ -29,25 +25,19 @@ public void clearIntegrations() {
@Test
public void testEnvironment() {

Response<String> response = ServiceClient.get(HOST + PATH_ENVIRONMENT);

TestUtils.assertTrue(response.isResponseOK());
String environment = OptimisationService.newIntegration(HOST).getEnvironment();

if (DEBUG) {
BasicLogger.debug(response.getBody());
BasicLogger.debug(environment);
}

TestUtils.assertTrue(environment.contains("HW"));
TestUtils.assertTrue(environment.contains("thread"));
}

@Test
public void testTest() {

Response<String> response = ServiceClient.get(HOST + PATH_TEST);

TestUtils.assertTrue(response.isResponseOK());

if (DEBUG) {
BasicLogger.debug(response.getBody());
}
TestUtils.assertTrue(OptimisationService.newIntegration(HOST).test().booleanValue());
}

@Test
Expand Down

0 comments on commit a8a43d6

Please sign in to comment.