From 5d2c2b94d6fdfe668f8c70340dc557ec6f3a6ad4 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Wed, 9 Oct 2013 09:15:59 +0200 Subject: [PATCH] Fixed remaining broken tests --- .../psi/fda/core/loops/cr/ScrlogicLoop.java | 6 +- .../ch/psi/fda/core/loops/OTFLoopTest.java | 5 +- .../core/loops/cr/ParallelCrlogicTest.java | 79 ++++++++----------- .../fda/core/loops/cr/ScrlogicLoopTest.java | 54 +++++++------ 4 files changed, 69 insertions(+), 75 deletions(-) diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/ScrlogicLoop.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/ScrlogicLoop.java index 553bc61..6528118 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/ScrlogicLoop.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/loops/cr/ScrlogicLoop.java @@ -116,8 +116,10 @@ public class ScrlogicLoop implements ActionLoop { @Override public void propertyChange(PropertyChangeEvent evt) { - DoubleTimestamp v = (DoubleTimestamp) evt.getNewValue(); - q.add(new TimestampedValue(v.getValue(), v.getTimestamp().getTime(), v.getNanosecondOffset())); + if(evt.getPropertyName().equals("value")){ + DoubleTimestamp v = (DoubleTimestamp) evt.getNewValue(); + q.add(new TimestampedValue(v.getValue(), v.getTimestamp().getTime(), v.getNanosecondOffset())); + } } }; sensor.addPropertyChangeListener(listener); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/OTFLoopTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/OTFLoopTest.java index 300f4fb..8c25cac 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/OTFLoopTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/OTFLoopTest.java @@ -162,10 +162,13 @@ public class OTFLoopTest { /** * Test method for {@link ch.psi.fda.core.loops.OTFLoop#execute()}. * Test abort functionality while executing an OTF scan + * @throws ExecutionException + * @throws ChannelException + * @throws TimeoutException * @throws CAException */ @Test - public void testExecuteAbort() throws InterruptedException { + public void testExecuteAbort() throws InterruptedException, TimeoutException, ChannelException, ExecutionException { // Data collector thread Thread t = new Thread(new TestCollector(loop.getDataQueue().getQueue())); diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java index 7dffe33..ba3d3dd 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ParallelCrlogicTest.java @@ -19,12 +19,13 @@ package ch.psi.fda.core.loops.cr; - -import gov.aps.jca.CAException; - import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import java.util.logging.Logger; import org.junit.After; @@ -32,42 +33,38 @@ import org.junit.Before; import org.junit.Test; import ch.psi.fda.TestConfiguration; -import ch.psi.fda.core.Sensor; import ch.psi.fda.core.actors.OTFActuator; import ch.psi.fda.core.messages.EndOfStreamMessage; import ch.psi.fda.core.messages.Message; -import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor; import ch.psi.fda.core.sensors.MillisecondTimestampSensor; import ch.psi.fda.core.sensors.OTFNamedChannelSensor; import ch.psi.fda.core.sensors.OTFScalerChannelSensor; -import ch.psi.jcae.ChannelBeanFactory; +import ch.psi.jcae.Channel; +import ch.psi.jcae.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; +import ch.psi.jcae.impl.DefaultChannelService; +import ch.psi.jcae.impl.type.DoubleTimestamp; -/** - * @author ebner - * - */ public class ParallelCrlogicTest { - // Get Logger private static final Logger logger = Logger.getLogger(ParallelCrlogicTest.class.getName()); - /** - * @throws java.lang.Exception - */ + private ChannelService cservice; + @Before public void setUp() throws Exception { + cservice = new DefaultChannelService(); } - /** - * @throws java.lang.Exception - */ @After public void tearDown() throws Exception { + cservice.destroy(); } // @Ignore @Test(timeout=60000) - public void testExecute() throws InterruptedException, CAException{ + public void testExecute() throws InterruptedException, ChannelException, TimeoutException, ExecutionException{ TestConfiguration c = TestConfiguration.getInstance(); @@ -80,19 +77,21 @@ public class ParallelCrlogicTest { double integrationTime = 0.01; double additionalBacklash = 0; - List sensors = new ArrayList(); - ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor("mot1", c.getMotor1()+".RVAL"); - ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("mot2", c.getMotor1()+".RBV"); - ChannelAccessDoubleSensor s3 = new ChannelAccessDoubleSensor("mot2", "ARIDI-PCT:CURRENT"); + List ids = new ArrayList<>(); + List> sensors = new ArrayList<>(); - sensors.add(s1); - sensors.add(s2); - sensors.add(s3); - - ScrlogicLoop scrlogic = new ScrlogicLoop(sensors); + ids.add("mot1"); + ids.add("mot2"); + ids.add("mot3"); + sensors.add(cservice.createChannel(new ChannelDescriptor<>(DoubleTimestamp.class, c.getMotor1()+".RVAL"))); + sensors.add(cservice.createChannel(new ChannelDescriptor<>(DoubleTimestamp.class, c.getMotor1()+".RBV"))); + sensors.add(cservice.createChannel(new ChannelDescriptor<>(DoubleTimestamp.class, "ARIDI-PCT:CURRENT"))); - CrlogicLoop crlogic = new CrlogicLoop(c.getCrlogicPrefix(), c.getServer(), c.getShare(), c.getSmbShare(), zigZag); + ScrlogicLoop scrlogic = new ScrlogicLoop(ids, sensors); + + + CrlogicLoop crlogic = new CrlogicLoop(cservice, c.getCrlogicPrefix(), c.getServer(), c.getShare(), c.getSmbShare(), zigZag); crlogic.setActor(new OTFActuator("cmot", c.getMotor1(), readback, start, end, stepSize, integrationTime, additionalBacklash)); crlogic.getSensors().add(new OTFNamedChannelSensor("trigger", "TRIGGER0")); crlogic.getSensors().add(new OTFScalerChannelSensor("scaler0", 0)); @@ -102,7 +101,9 @@ public class ParallelCrlogicTest { // Initialize scaler template VSC16ScalerChannelsTemplate scalertemplate = new VSC16ScalerChannelsTemplate(); - ChannelBeanFactory.getFactory().createChannelBeans(scalertemplate, c.getPrefixScaler()); + Map macros = new HashMap<>(); + macros.put("PREFIX", c.getPrefixScaler()); + cservice.createAnnotatedChannels(scalertemplate, macros); ParallelCrlogic pcrlogic = new ParallelCrlogic(crlogic, scrlogic); @@ -126,27 +127,9 @@ public class ParallelCrlogicTest { } // Destroy scaler template - ChannelBeanFactory.getFactory().destroyChannelBeans(scalertemplate); + cservice.destroyAnnotatedChannels(scalertemplate); pcrlogic.destroy(); - - -// System.out.println("CRLOGIC data:"); -// BlockingQueue queue = crlogic.getDataQueue().getQueue(); -// Message m = queue.take(); -// while(! (m instanceof EndOfStreamMessage)){ -// System.out.println(m.toString()); -// m = queue.take(); -// } -// -// -// System.out.println("SCRLOGIC data:"); -// queue = scrlogic.getDataQueue().getQueue(); -// m = queue.take(); -// while(! (m instanceof EndOfStreamMessage)){ -// System.out.println(m.toString()); -// m = queue.take(); -// } } } diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ScrlogicLoopTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ScrlogicLoopTest.java index 84e3fd4..41c5ce1 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ScrlogicLoopTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/core/loops/cr/ScrlogicLoopTest.java @@ -19,64 +19,70 @@ package ch.psi.fda.core.loops.cr; -import gov.aps.jca.CAException; - import java.util.ArrayList; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; import org.junit.Test; -import ch.psi.fda.core.Sensor; import ch.psi.fda.core.messages.EndOfStreamMessage; import ch.psi.fda.core.messages.Message; -import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor; -import ch.psi.jcae.ChannelBean; -import ch.psi.jcae.ChannelBeanFactory; +import ch.psi.jcae.Channel; +import ch.psi.jcae.ChannelDescriptor; +import ch.psi.jcae.ChannelException; +import ch.psi.jcae.ChannelService; +import ch.psi.jcae.impl.DefaultChannelService; +import ch.psi.jcae.impl.type.DoubleTimestamp; -/** - * @author ebner - * - */ public class ScrlogicLoopTest { - /** - * @throws java.lang.Exception - */ + private ChannelService cservice; + @Before public void setUp() throws Exception { + cservice = new DefaultChannelService(); } - /** - * @throws java.lang.Exception - */ @After public void tearDown() throws Exception { + cservice.destroy(); } /** * Test method for {@link ch.psi.fda.core.loops.cr.ScrlogicLoop#execute()}. * @throws InterruptedException + * @throws TimeoutException + * @throws ChannelException * @throws CAException */ @Test - public void testExecute() throws InterruptedException, CAException { + public void testExecute() throws InterruptedException, ChannelException, TimeoutException { System.out.println("For this test the motor MTEST-HW3:MOT1 need to be moved manually"); - List sensors = new ArrayList(); - ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor("mot1", "MTEST-HW3:MOT1.RBV"); - ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("mot2", "MTEST-HW3:MOT1"); +// List sensors = new ArrayList(); +// ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor("mot1", "MTEST-HW3:MOT1.RBV"); +// ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("mot2", "MTEST-HW3:MOT1"); - sensors.add(s1); - sensors.add(s2); +// sensors.add(s1); +// sensors.add(s2); - final ScrlogicLoop logic = new ScrlogicLoop(sensors); + List ids = new ArrayList<>(); + List> sensors = new ArrayList<>(); + + ids.add("mot1"); + ids.add("mot2"); + sensors.add(cservice.createChannel(new ChannelDescriptor<>(DoubleTimestamp.class, "MTEST-HW3:MOT1.RBV"))); + sensors.add(cservice.createChannel(new ChannelDescriptor<>(DoubleTimestamp.class, "MTEST-HW3:MOT1"))); + + + final ScrlogicLoop logic = new ScrlogicLoop(ids, sensors); for(int i=0;i<2;i++){ @@ -104,7 +110,7 @@ public class ScrlogicLoopTest { @Override public void run() { try{ - ChannelBean channel = ChannelBeanFactory.getFactory().createChannelBean(Double.class, "MTEST-HW3:MOT1", false); + Channel channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, "MTEST-HW3:MOT1", false)); // Wait some time until Thread.sleep(100); channel.setValue(1.5);