Skip to content

Commit 4d6d4d8

Browse files
committed
Put/Write: Pass errors within client (not connected, ...) or from server
(no write access, other error reported by server) back up
1 parent 588f2ce commit 4d6d4d8

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

core/pva/src/main/java/org/epics/pva/client/PutRequest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019-2020 Oak Ridge National Laboratory.
2+
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -153,7 +153,7 @@ public void handleResponse(final ByteBuffer buffer) throws Exception
153153
final byte subcmd = buffer.get();
154154
PVAStatus status = PVAStatus.decode(buffer);
155155
if (! status.isSuccess())
156-
throw new Exception(channel + " Put Response for " + request + ": " + status);
156+
fail(new Exception(channel + " Put Response for " + request + ": " + status));
157157

158158
if (subcmd == PVAHeader.CMD_SUB_INIT)
159159
{
@@ -186,9 +186,15 @@ else if (subcmd == PVAHeader.CMD_SUB_DESTROY)
186186
complete(null);
187187
}
188188
else
189-
throw new Exception("Cannot decode Put " + subcmd + " Reply #" + request_id);
189+
fail(new Exception("Cannot decode Put " + subcmd + " Reply #" + request_id));
190190
}
191191

192+
/** Handle failure by both notifying whoever waits for this request to complete
193+
* and by throwing exception
194+
*
195+
* @param ex Error description
196+
* @throws Exception
197+
*/
192198
private void fail(final Exception ex) throws Exception
193199
{
194200
completeExceptionally(ex);

core/pva/src/test/java/org/epics/pva/client/ClientDemo.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019-2020 Oak Ridge National Laboratory.
2+
* Copyright (c) 2019-2022 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -263,18 +263,39 @@ public void testStatic() throws Exception
263263
pva.close();
264264
}
265265

266+
/** Write ('put') test
267+
*
268+
* Includes a pause to allow manual stopping of the server.
269+
*
270+
* May be used with read-only access security on IOC
271+
* to test failed write.
272+
*/
266273
@Test
267274
public void testPut() throws Exception
268275
{
269276
// Create a client
270277
final PVAClient pva = new PVAClient();
271278

272279
// Connect to one or more channels
273-
final PVAChannel channel = pva.getChannel("ramp");
280+
final PVAChannel channel = pva.getChannel("saw");
274281
channel.connect().get(5, TimeUnit.SECONDS);
275282

283+
284+
System.out.println("CONNECTED!");
285+
System.out.println("Optionally stop the IOC within the next 10 seconds...");
286+
TimeUnit.SECONDS.sleep(10);
287+
System.out.println("Writing '2'...");
288+
276289
// Write data
277-
channel.write("value", 2.0).get(2, TimeUnit.SECONDS);
290+
try
291+
{
292+
channel.write("value", 2.0).get(2, TimeUnit.SECONDS);
293+
}
294+
catch (Exception ex)
295+
{
296+
System.out.println("Write failed");
297+
ex.printStackTrace();
298+
}
278299

279300
// Close channels
280301
channel.close();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Test read-only PVs:
2+
#
3+
# softIocPVA -m N='' -d demo.db -a demo.acf
4+
5+
ASG(DEFAULT)
6+
{
7+
RULE(1, READ)
8+
}

0 commit comments

Comments
 (0)