added simulated epics server for testing

This commit is contained in:
2016-03-21 15:47:04 +01:00
parent 5f836e7856
commit c5d845e7ff
4 changed files with 152 additions and 2 deletions

View File

@@ -30,7 +30,7 @@ dependencies {
compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.5.1'
compile 'org.glassfish.jersey.media:jersey-media-sse:2.5.1'
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.5.1'
compile 'org.zeromq:jeromq:0.3.5'
compile 'org.zeromq:jeromq:0.3.4'
compile 'org.apache.commons:cli:1.2'
// For reading/writing Matlab files
compile 'com.jmatio:jmatio:0.2u2psi1'

View File

@@ -38,6 +38,7 @@ import com.google.common.eventbus.Subscribe;
import ch.psi.fda.core.TestChannels;
import ch.psi.fda.aq.Manipulator;
import ch.psi.fda.core.CAJTestServer;
import ch.psi.fda.core.Manipulation;
import ch.psi.fda.core.manipulator.JythonManipulation;
import ch.psi.fda.core.scripting.JythonParameterMapping;
@@ -59,16 +60,21 @@ public class ManipulatorTest {
private EventBus bus;
private ChannelService cservice;
private CAJTestServer server;
@Before
public void setUp() throws Exception {
bus = new EventBus();
cservice = new DefaultChannelService();
server = new CAJTestServer();
server.runInSeparateThread();
}
@After
public void tearDown() throws Exception {
cservice.destroy();
server.destroy();
}
@Test

View File

@@ -0,0 +1,144 @@
package ch.psi.fda.core;
import gov.aps.jca.CAException;
import gov.aps.jca.JCALibrary;
import gov.aps.jca.cas.ServerContext;
import gov.aps.jca.dbr.DBR_Double;
import gov.aps.jca.dbr.DBR_Enum;
import gov.aps.jca.dbr.DBR_Int;
import gov.aps.jca.dbr.DBR_String;
import com.cosylab.epics.caj.cas.util.DefaultServerImpl;
import com.cosylab.epics.caj.cas.util.MemoryProcessVariable;
import com.cosylab.epics.caj.cas.util.examples.CounterProcessVariable;
public class CAJTestServer {
/**
* JCA server context.
*/
private volatile ServerContext context = null;
/**
* Initialize JCA context.
* @throws CAException throws on any failure.
*/
private void initialize() throws CAException {
// Get the JCALibrary instance.
JCALibrary jca = JCALibrary.getInstance();
// Create server implementation
DefaultServerImpl server = new DefaultServerImpl();
// Create a context with default configuration values.
context = jca.createServerContext(JCALibrary.CHANNEL_ACCESS_SERVER_JAVA, server);
// register process variables
registerProcessVariables(server);
}
/**
* Register process variables.
* @param server
*/
private void registerProcessVariables(DefaultServerImpl server) {
// simple in-memory PV
server.createMemoryProcessVariable(TestChannels.BINARY_OUT, DBR_Int.TYPE, new int[]{0});
server.createMemoryProcessVariable(TestChannels.BINARY_OUT_TWO, DBR_Int.TYPE, new int[]{0});
server.createMemoryProcessVariable(TestChannels.ANALOG_OUT, DBR_Double.TYPE, new double[] {0.0});
server.createMemoryProcessVariable(TestChannels.STRING_OUT, DBR_String.TYPE, new String[]{"hello"});
// simple in-memory 1MB array
final double[] arrayValue = new double[1024*1024];
for (int i = 0; i < arrayValue.length; i++)
arrayValue[i] = i;
server.createMemoryProcessVariable(TestChannels.DOUBLE_WAVEFORM, DBR_Double.TYPE, arrayValue);
}
/**
* Destroy JCA server context.
*/
public void destroy() {
try {
// Destroy the context, check if never initialized.
if (context != null)
context.destroy();
} catch (Throwable th) {
th.printStackTrace();
}
}
/**
* @param channelName
*/
public void execute() {
try {
// initialize context
initialize();
// Display basic information about the context.
System.out.println(context.getVersion().getVersionString());
context.printInfo(); System.out.println();
System.out.println("Running server...");
// run server
context.run(0);
System.out.println("Done.");
} catch (Throwable th) {
th.printStackTrace();
}
finally {
// always finalize
destroy();
}
}
public void runInSeparateThread()
{
try {
// initialize context
initialize();
// run server
new Thread(new Runnable() {
@Override
public void run() {
try {
context.run(0);
} catch(Throwable th) {
th.printStackTrace();
}
}
}).start();
} catch (Throwable th) {
throw new RuntimeException("Failed to start CA server.", th);
}
}
/**
* Program entry point.
* @param args command-line arguments
*/
public static void main(String[] args) {
// execute
new CAJTestServer().execute();
}
}

View File

@@ -39,7 +39,7 @@ public class CrlogicLoopStreamTest {
private static final Logger logger = Logger.getLogger(CrlogicLoopStreamTest.class.getName());
@Ignore
@Test(timeout=60000)
public void testExecute() throws InterruptedException, ChannelException, TimeoutException, ExecutionException{