Skip to content

Commit

Permalink
DAQ-3058 Enable MalcolmEpicsV4ConnectorTest, ExampleMalcolmDeviceTest
Browse files Browse the repository at this point in the history
This uses a horrible workaround with reflection but there doesn't
appear to be another solution until
epics-base/epicsCoreJava#100 is addressed.

The other option would be to skip these tests but they are fairly
essential to the Malcolm scanning infrastructure.

Change-Id: I3c96eb2de4b5133659854c74427bb993f9443e8e
  • Loading branch information
joeshannon committed Aug 18, 2020
1 parent 325cf95 commit 2ffeafb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.eclipse.scanning.example.malcolm;

import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

import org.epics.pvaccess.server.ServerContext;
import org.epics.pvaccess.server.impl.remote.ServerContextImpl;
import org.epics.pvdata.pv.PVStructure;
import org.epics.pvdatabase.PVDatabase;
import org.epics.pvdatabase.PVDatabaseFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This class creates an Epics V4 service, that listens for connections and handles RPC, GET, PUT etc. The modelled
Expand All @@ -23,6 +28,7 @@ public abstract class AbstractEPICSv4Device implements IEPICSv4Device {
protected static int traceLevel = 0;
protected final CountDownLatch latch = new CountDownLatch(1);
protected DummyMalcolmRecord pvRecord = null;
private static final Logger logger = LoggerFactory.getLogger(AbstractEPICSv4Device.class);

public AbstractEPICSv4Device(String deviceName) {
recordName = deviceName;
Expand All @@ -49,13 +55,45 @@ public void start() throws Exception {
pvRecord = DummyMalcolmRecord.create(recordName);
pvRecord.setTraceLevel(traceLevel);
master.addRecord(pvRecord);
ServerContext context = ServerContextImpl.startPVAServer(getPvaProviderName(), 0, true,
System.out);
ServerContext context = startPvaServerWithReflection(getPvaProviderName(), 0, true, System.out);
logger.info("PVA Server Started");
latch.await();
master.removeRecord(pvRecord);
context.destroy();
}

protected abstract String getPvaProviderName();


// TODO replace this once there is a solution to https://github.com/epics-base/epicsCoreJava/issues/100
/**
* Since Tycho runs in OSGi it cannot see internal class from EpicsV4:
* {@code org.epics.pvaccess.server.impl.remote.ServerContextImpl}
* <p>
* The Epics library currently provides no other exported API mechanism to
* start a PVA server apart from ServerFactory.create() but this is not good
* for tests as there is no way to stop the created server.
* <p>
* This workaround uses reflection to call the method and return the result as a
* ServerContext interface object which is from an exported package.
* <p>
* Keep checking <a href="https://github.com/epics-base/epicsCoreJava/issues/100"> the issue
* for solution so this can be removed.
*/
private ServerContext startPvaServerWithReflection(String providerNames, int timeToRun,
boolean runInSeparateThread, PrintStream printInfoStream) throws Exception {
String implClassName = "org.epics.pvaccess.server.impl.remote.ServerContextImpl";
Class<?> implClass;
Bundle bundle = FrameworkUtil.getBundle(ServerContext.class);
if (bundle != null) {
implClass = bundle.loadClass(implClassName);
} else {
implClass = Class.forName(implClassName);
}
Method startPvaMethod = implClass.getMethod("startPVAServer", String.class, int.class, boolean.class,
PrintStream.class);
return (ServerContext) startPvaMethod.invoke(null, providerNames, timeToRun, runInSeparateThread,
printInfoStream);
}

}
3 changes: 0 additions & 3 deletions org.eclipse.scanning.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
<version>${tycho.version}</version>
<configuration>
<excludes>
<!-- connects to external service -->
<exclude>ExampleMalcolmDeviceTest</exclude>
<exclude>MalcolmEpicsV4ConnectorTest</exclude>
<!-- PsuedoSpringParser to be removed -->
<exclude>PseudoSpringParserTest</exclude>
<!-- Powermock issues -->
Expand Down

0 comments on commit 2ffeafb

Please sign in to comment.