-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
182e835
commit 41a4194
Showing
5 changed files
with
325 additions
and
112 deletions.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
vcell-server/src/test/java/cbit/vcell/message/server/dispatcher/DispatcherTestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package cbit.vcell.message.server.dispatcher; | ||
|
||
import cbit.vcell.geometry.Geometry; | ||
import cbit.vcell.mapping.MathSymbolMapping; | ||
import cbit.vcell.math.*; | ||
import cbit.vcell.mathmodel.MathModel; | ||
import cbit.vcell.parser.ExpressionBindingException; | ||
import cbit.vcell.resource.PropertyLoader; | ||
import cbit.vcell.server.HtcJobID; | ||
import cbit.vcell.server.SimulationExecutionStatus; | ||
import cbit.vcell.server.SimulationJobStatus; | ||
import cbit.vcell.solver.MeshSpecification; | ||
import cbit.vcell.solver.Simulation; | ||
import cbit.vcell.solver.VCSimulationIdentifier; | ||
import cbit.vcell.solver.server.SimulationMessage; | ||
import org.vcell.util.DataAccessException; | ||
import org.vcell.util.ISize; | ||
import org.vcell.util.document.*; | ||
|
||
import java.beans.PropertyVetoException; | ||
import java.sql.SQLException; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
public class DispatcherTestUtils { | ||
private static String previousServerID = ""; | ||
private static String previousHtcMax = ""; | ||
private static String previousHtcMin = ""; | ||
private static String previousHtcPowerFloor = ""; | ||
private static String previousMongoBlob = ""; | ||
private static String previousJMSIntHostProperty = ""; | ||
private static String previousJMSIntPortProperty = ""; | ||
private static String previousSimJMSIntHostProperty = ""; | ||
private static String previousSimJMSIntPortProperty = ""; | ||
private static String previousHTCHost = ""; | ||
private static String previousHTCUser = ""; | ||
private static String previousHTCUserKeyFile = ""; | ||
private static String previousMaxJobsPerScan = ""; | ||
|
||
public static final VCellServerID testVCellServerID = VCellServerID.getServerID("test"); | ||
public static final MockVCMessageSession testMessageSession = new MockVCMessageSession(); | ||
public static final int jobIndex = 0; | ||
public static final int taskID = 0; | ||
public static final KeyValue simKey = new KeyValue("0"); | ||
public static User alice = new User("Alice", new KeyValue("0")); | ||
public static User bob = new User("Bob", new KeyValue("1")); | ||
public static final VCSimulationIdentifier simID = new VCSimulationIdentifier(simKey, alice); | ||
|
||
public static void setRequiredProperties(){ | ||
previousServerID = PropertyLoader.getProperty(PropertyLoader.vcellServerIDProperty, ""); | ||
PropertyLoader.setProperty(PropertyLoader.vcellServerIDProperty, ""); | ||
|
||
previousHtcMax = PropertyLoader.getProperty(PropertyLoader.htcMaxMemoryMB, ""); | ||
PropertyLoader.setProperty(PropertyLoader.htcMaxMemoryMB, "4096"); | ||
|
||
previousHtcMin = PropertyLoader.getProperty(PropertyLoader.htcMinMemoryMB, ""); | ||
PropertyLoader.setProperty(PropertyLoader.htcMinMemoryMB, "1024"); | ||
|
||
previousHtcPowerFloor = PropertyLoader.getProperty(PropertyLoader.htcPowerUserMemoryFloorMB, ""); | ||
PropertyLoader.setProperty(PropertyLoader.htcPowerUserMemoryFloorMB, "51200"); | ||
|
||
previousMongoBlob = PropertyLoader.getProperty(PropertyLoader.jmsBlobMessageUseMongo, ""); | ||
PropertyLoader.setProperty(PropertyLoader.jmsBlobMessageUseMongo, ""); | ||
|
||
previousJMSIntHostProperty = PropertyLoader.getProperty(PropertyLoader.jmsIntHostInternal, ""); | ||
PropertyLoader.setProperty(PropertyLoader.jmsIntHostInternal, "host"); | ||
|
||
previousJMSIntPortProperty = PropertyLoader.getProperty(PropertyLoader.jmsIntPortInternal, ""); | ||
PropertyLoader.setProperty(PropertyLoader.jmsIntPortInternal, "80"); | ||
|
||
previousSimJMSIntHostProperty = PropertyLoader.getProperty(PropertyLoader.jmsSimHostInternal, ""); | ||
PropertyLoader.setProperty(PropertyLoader.jmsSimHostInternal, "host"); | ||
|
||
previousSimJMSIntPortProperty = PropertyLoader.getProperty(PropertyLoader.jmsSimPortInternal, ""); | ||
PropertyLoader.setProperty(PropertyLoader.jmsSimPortInternal, "80"); | ||
|
||
previousHTCHost = PropertyLoader.getProperty(PropertyLoader.htcHosts, ""); | ||
PropertyLoader.setProperty(PropertyLoader.htcHosts, "host"); | ||
|
||
previousHTCUser = PropertyLoader.getProperty(PropertyLoader.htcUser, ""); | ||
PropertyLoader.setProperty(PropertyLoader.htcUser, "user"); | ||
|
||
previousHTCUserKeyFile = PropertyLoader.getProperty(PropertyLoader.htcUserKeyFile, ""); | ||
PropertyLoader.setProperty(PropertyLoader.htcUserKeyFile, "keyFile"); | ||
|
||
previousMaxJobsPerScan = PropertyLoader.getProperty(PropertyLoader.maxJobsPerScan, ""); | ||
PropertyLoader.setProperty(PropertyLoader.maxJobsPerScan, "100"); | ||
} | ||
|
||
public static void restoreRequiredProperties(){ | ||
PropertyLoader.setProperty(PropertyLoader.vcellServerIDProperty, previousServerID); | ||
PropertyLoader.setProperty(PropertyLoader.htcMaxMemoryMB, previousHtcMax); | ||
PropertyLoader.setProperty(PropertyLoader.htcMinMemoryMB, previousHtcMin); | ||
PropertyLoader.setProperty(PropertyLoader.htcPowerUserMemoryFloorMB, previousHtcPowerFloor); | ||
PropertyLoader.setProperty(PropertyLoader.jmsBlobMessageUseMongo, previousMongoBlob); | ||
PropertyLoader.setProperty(PropertyLoader.jmsIntPortInternal, previousJMSIntPortProperty); | ||
PropertyLoader.setProperty(PropertyLoader.jmsIntHostInternal, previousJMSIntHostProperty); | ||
PropertyLoader.setProperty(PropertyLoader.jmsSimPortInternal, previousSimJMSIntPortProperty); | ||
PropertyLoader.setProperty(PropertyLoader.jmsSimHostInternal, previousSimJMSIntHostProperty); | ||
PropertyLoader.setProperty(PropertyLoader.htcHosts, previousHTCHost); | ||
PropertyLoader.setProperty(PropertyLoader.htcUser, previousHTCUser); | ||
PropertyLoader.setProperty(PropertyLoader.htcUserKeyFile, previousHTCUserKeyFile); | ||
PropertyLoader.setProperty(PropertyLoader.maxJobsPerScan, previousMaxJobsPerScan); | ||
} | ||
|
||
public static Simulation createMockSimulation(int iSizeX, int iSizeY, int iSizeZ) throws PropertyVetoException, MathException, ExpressionBindingException { | ||
VolVariable volVariable = new VolVariable("t", new Variable.Domain(new CompartmentSubDomain("t", 1))); | ||
VolVariable volVariable2 = new VolVariable("b", new Variable.Domain(new CompartmentSubDomain("b", 2))); | ||
MathSymbolMapping mathSymbolMapping = new MathSymbolMapping(); | ||
Geometry geometry = new Geometry("T", 3); | ||
MathModel mathModel = new MathModel(new Version("Test", alice)); | ||
MathDescription mathDescription = new MathDescription("Test", mathSymbolMapping); | ||
mathDescription.setGeometry(new Geometry("T", 3)); | ||
Simulation simulation = new Simulation(SimulationVersion.createTempSimulationVersion(), | ||
mathDescription, mathModel); | ||
MeshSpecification meshSpecification = new MeshSpecification(geometry); | ||
meshSpecification.setSamplingSize(new ISize(iSizeX, iSizeY, iSizeZ)); | ||
simulation.setMeshSpecification(meshSpecification); | ||
mathDescription.setAllVariables(new Variable[]{volVariable, volVariable2}); | ||
return simulation; | ||
} | ||
|
||
public static void insertOrUpdateStatus(KeyValue simKey, int jobIndex, int taskID, User user, SimulationJobStatus.SchedulerStatus status, SimulationDatabase simulationDB) throws SQLException, DataAccessException { | ||
SimulationJobStatus jobStatus = simulationDB.getLatestSimulationJobStatus(simKey, jobIndex); | ||
VCSimulationIdentifier simID = new VCSimulationIdentifier(simKey, user); | ||
SimulationJobStatus simulationJobStatus = new SimulationJobStatus(testVCellServerID, simID, jobIndex, Date.from(Instant.now()), status, taskID, | ||
SimulationMessage.workerAccepted("accepted"), null, | ||
new SimulationExecutionStatus(Date.from(Instant.now()), "", | ||
Date.from(Instant.now()), Date.from(Instant.now()), false, new HtcJobID("2", HtcJobID.BatchSystemType.SLURM))); | ||
if (jobStatus == null){ | ||
simulationDB.insertSimulationJobStatus(simulationJobStatus); | ||
} else { | ||
simulationDB.updateSimulationJobStatus(simulationJobStatus); | ||
} | ||
} | ||
|
||
public static void insertOrUpdateStatus(KeyValue simKey, int jobIndex, int taskID, User user, SimulationDatabase simulationDB) throws SQLException, DataAccessException { | ||
insertOrUpdateStatus(simKey, jobIndex, taskID, user, SimulationJobStatus.SchedulerStatus.RUNNING, simulationDB); | ||
} | ||
|
||
/** | ||
Defaults to a running status. | ||
*/ | ||
public static void insertOrUpdateStatus(SimulationDatabase simulationDatabase) throws SQLException, DataAccessException { | ||
insertOrUpdateStatus(simKey, jobIndex, taskID, alice, simulationDatabase); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
vcell-server/src/test/java/cbit/vcell/message/server/dispatcher/MockMessagingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cbit.vcell.message.server.dispatcher; | ||
|
||
import cbit.vcell.message.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MockMessagingService implements VCMessagingService { | ||
|
||
public ArrayList<VCMessagingConsumer> messagingConsumers = new ArrayList<>(); | ||
|
||
@Override | ||
public VCMessageSession createProducerSession() { | ||
return new MockVCMessageSession(); | ||
} | ||
|
||
@Override | ||
public void addMessageConsumer(VCMessagingConsumer vcMessagingConsumer) { | ||
messagingConsumers.add(vcMessagingConsumer); | ||
} | ||
|
||
@Override | ||
public void removeMessageConsumer(VCMessagingConsumer vcMessagingConsumer) { | ||
|
||
} | ||
|
||
@Override | ||
public List<VCMessagingConsumer> getMessageConsumers() { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public void close() throws VCMessagingException { | ||
|
||
} | ||
|
||
@Override | ||
public VCMessageSelector createSelector(String clientMessageFilter) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public VCMessagingDelegate getDelegate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setConfiguration(VCMessagingDelegate delegate, String jmshost, int jmsport) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...l-server/src/test/java/cbit/vcell/message/server/dispatcher/SimulationDispatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cbit.vcell.message.server.dispatcher; | ||
|
||
import cbit.vcell.server.SimulationJobStatus; | ||
import cbit.vcell.server.SimulationStatus; | ||
import org.junit.jupiter.api.*; | ||
import org.vcell.util.DataAccessException; | ||
import org.vcell.util.document.User; | ||
|
||
import java.sql.SQLException; | ||
|
||
@Tag("Fast") | ||
public class SimulationDispatcherTest { | ||
private final static User testUser = DispatcherTestUtils.alice; | ||
private MockSimulationDB mockSimulationDB = new MockSimulationDB(); | ||
private MockMessagingService mockMessagingServiceInternal = new MockMessagingService(); | ||
private MockMessagingService mockMessagingServiceSim = new MockMessagingService(); | ||
|
||
@BeforeAll | ||
public static void setSystemProperties(){ | ||
DispatcherTestUtils.setRequiredProperties(); | ||
} | ||
|
||
@AfterAll | ||
public static void restoreSystemProperties(){ | ||
DispatcherTestUtils.restoreRequiredProperties(); | ||
} | ||
|
||
@BeforeEach | ||
public void beforeEach(){ | ||
mockSimulationDB = new MockSimulationDB(); | ||
} | ||
|
||
|
||
@Test | ||
public void onStartRequestTest() throws DataAccessException, SQLException { | ||
SimulationDispatcher simulationDispatcher = SimulationDispatcher.simulationDispatcherCreator(mockSimulationDB, mockMessagingServiceInternal, mockMessagingServiceSim); | ||
SimulationStatus simStatus = simulationDispatcher.simServiceImpl.startSimulation(testUser, DispatcherTestUtils.simID, 1); | ||
SimulationJobStatus jobStatus = mockSimulationDB.getLatestSimulationJobStatus(DispatcherTestUtils.simKey, 0); | ||
Assertions.assertTrue(jobStatus.getSchedulerStatus().isWaiting()); | ||
} | ||
|
||
@Test | ||
public void onStopRequestTest() throws DataAccessException, SQLException { | ||
DispatcherTestUtils.insertOrUpdateStatus(mockSimulationDB); | ||
SimulationDispatcher simulationDispatcher = SimulationDispatcher.simulationDispatcherCreator(mockSimulationDB, mockMessagingServiceInternal, mockMessagingServiceSim); | ||
SimulationStatus simStatus = simulationDispatcher.simServiceImpl.stopSimulation(testUser, DispatcherTestUtils.simID); | ||
SimulationJobStatus jobStatus = mockSimulationDB.getLatestSimulationJobStatus(DispatcherTestUtils.simKey, 0); | ||
Assertions.assertTrue(jobStatus.getSchedulerStatus().isStopped()); | ||
} | ||
|
||
} |
Oops, something went wrong.