1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package com.cosylab.epics.caj.impl.handlers.test;
16
17 import gov.aps.jca.CAException;
18 import gov.aps.jca.CAStatus;
19 import gov.aps.jca.Channel;
20 import gov.aps.jca.TimeoutException;
21 import gov.aps.jca.dbr.DBR;
22 import gov.aps.jca.event.GetEvent;
23 import gov.aps.jca.event.GetListener;
24
25 import com.cosylab.epics.caj.CAJContext;
26
27 import junit.framework.TestCase;
28
29
30
31
32
33
34 public class ExceptionResponseTest extends TestCase {
35
36 private class GetListenerImpl implements GetListener
37 {
38 public DBR value = null;
39 public CAStatus status = null;
40
41
42
43
44 public synchronized void getCompleted(GetEvent ev) {
45 status = ev.getStatus();
46 value = ev.getDBR();
47 this.notifyAll();
48 }
49 }
50
51
52
53
54 private CAJContext context;
55
56
57
58
59 private Channel channel;
60
61
62
63
64
65 public ExceptionResponseTest(String methodName) {
66 super(methodName);
67 }
68
69
70
71
72 public void testExceptionResponse() throws CAException, TimeoutException, InterruptedException {
73 GetListenerImpl listener = new GetListenerImpl();
74 channel.get(0xFFFF, listener);
75 synchronized (listener)
76 {
77 context.flushIO();
78 listener.wait(3000);
79 }
80 assertEquals(CAStatus.GETFAIL, listener.status);
81 }
82
83
84
85
86 protected void setUp() throws Exception {
87 context = new CAJContext();
88 channel = context.createChannel("record1");
89 context.pendIO(5.0);
90 assertEquals(Channel.CONNECTED, channel.getConnectionState());
91 }
92
93
94
95
96 protected void tearDown() throws Exception {
97 if (!context.isDestroyed())
98 context.destroy();
99 context = null;
100 }
101
102
103
104
105
106 public static void main(String[] args) {
107 junit.textui.TestRunner.run(ExceptionResponseTest.class);
108 }
109
110 }