Skip to content

Commit 2584e2c

Browse files
committed
gpclient: Javadoc update
1 parent e138af2 commit 2584e2c

2 files changed

Lines changed: 104 additions & 9 deletions

File tree

gpclient/gpclient-core/src/main/java/org/epics/gpclient/PVEventRecorder.java

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public List<PVEvent> getEvents() {
5656
}
5757
}
5858

59+
/**
60+
* Waits until the condition is met. If the conditions is already met, it
61+
* returns right away. If the condition is not met after the time specified,
62+
* an {@link AssertionError} is thrown.
63+
*
64+
* @param ms the timeout in millis
65+
* @param condition the condition
66+
*/
5967
public void wait(int ms, Function<List<PVEvent>, Boolean> condition) {
6068
CountDownLatch latch = new CountDownLatch(1);
6169
Runnable newTest = new Runnable() {
@@ -83,6 +91,15 @@ public void run() {
8391
}
8492
}
8593

94+
/**
95+
* Checks that the condition is not met. The method returns successfully
96+
* only if the condition is not met within the timeout. If the conditions is
97+
* already met, or if it is met within the time specified, an
98+
* {@link AssertionError} is thrown.
99+
*
100+
* @param ms the timeout in millis
101+
* @param condition the condition
102+
*/
86103
public void dontExpect(int ms, Function<List<PVEvent>, Boolean> condition) {
87104
CountDownLatch latch = new CountDownLatch(1);
88105
Runnable newTest = new Runnable() {
@@ -109,17 +126,34 @@ public void run() {
109126
throw new AssertionError("Received " + condition + " against expectation");
110127
}
111128
}
112-
129+
130+
/**
131+
* Returns an {@link AssertionError} if the condition is not already met.
132+
*
133+
* @param condition the condition
134+
*/
113135
public void hasReceived(Function<List<PVEvent>, Boolean> condition) {
114136
if (!condition.apply(events)) {
115137
throw new AssertionError("Didn't receive " + condition);
116138
}
117139
}
118140

119-
public boolean hasNotReceived(Function<List<PVEvent>, Boolean> condition) {
120-
return !condition.apply(events);
141+
/**
142+
* Returns an {@link AssertionError} if the condition is already met.
143+
*
144+
* @param condition the condition
145+
*/
146+
public void hasNotReceived(Function<List<PVEvent>, Boolean> condition) {
147+
if (condition.apply(events)) {
148+
throw new AssertionError("Received " + condition);
149+
}
121150
}
122151

152+
/**
153+
* Checks that any event was received.
154+
*
155+
* @return any event condition
156+
*/
123157
public static Function<List<PVEvent>, Boolean> forAnEvent() {
124158
return new Function<List<PVEvent>, Boolean>() {
125159
@Override
@@ -134,10 +168,21 @@ public String toString() {
134168
};
135169
}
136170

171+
/**
172+
* Checks that a connection event was received.
173+
*
174+
* @return connection event condition
175+
*/
137176
public static Function<List<PVEvent>, Boolean> forAConnectionEvent() {
138177
return anEventOfType(PVEvent.Type.READ_CONNECTION);
139178
}
140179

180+
/**
181+
* Checks that an event of the given type was received.
182+
*
183+
* @param type the event type
184+
* @return type of event condition
185+
*/
141186
public static Function<List<PVEvent>, Boolean> anEventOfType(PVEvent.Type type) {
142187
return new Function<List<PVEvent>, Boolean>() {
143188
@Override
@@ -151,7 +196,13 @@ public String toString() {
151196
}
152197
};
153198
}
154-
199+
200+
/**
201+
* Checks the given number of events were received.
202+
*
203+
* @param count the number of events
204+
* @return event count condition
205+
*/
155206
public static Function<List<PVEvent>, Boolean> forEventCount(final int count) {
156207
return new Function<List<PVEvent>, Boolean>() {
157208
@Override

gpclient/gpclient-core/src/main/java/org/epics/gpclient/ProbeCollector.java

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.io.PrintStream;
88

99
/**
10+
* Utility class used to test the communication between the collectors and the
11+
* data providers.
1012
*
1113
* @author carcassi
1214
*/
@@ -16,6 +18,13 @@ public class ProbeCollector<T> {
1618
private final ReadCollector<T, T> readCollector;
1719
private final WriteCollector<T> writeCollector;
1820

21+
/**
22+
* Creates a probe collector that reads/writes the given type and that
23+
* streams events to the given output.
24+
*
25+
* @param type the type of objects to read/write
26+
* @param out where to stream the log
27+
*/
1928
public ProbeCollector(Class<T> type, PrintStream out) {
2029
this.readCollector = new LatestValueCollector<>(type);
2130
this.writeCollector = new WriteCollector<>();
@@ -39,33 +48,68 @@ protected void onEvent(PVEvent event) {
3948
this.readCollector.setUpdateListener(this.recorder);
4049
this.writeCollector.setUpdateListener(this.recorder);
4150
}
42-
51+
52+
/**
53+
* The current connection value in the collector.
54+
*
55+
* @return the connection value
56+
*/
4357
public boolean getConnection() {
4458
return readCollector.getConnection();
4559
}
46-
60+
61+
/**
62+
* The current value in the collector.
63+
*
64+
* @return the value
65+
*/
4766
public T getValue() {
4867
return readCollector.getValue();
4968
}
5069

70+
/**
71+
* The read collector to send events to.
72+
*
73+
* @return the read collector
74+
*/
5175
public ReadCollector<T, T> getReadCollector() {
5276
return readCollector;
5377
}
5478

79+
/**
80+
* The write collector to send events to.
81+
*
82+
* @return the write collector
83+
*/
5584
public WriteCollector<T> getWriteCollector() {
5685
return writeCollector;
5786
}
58-
87+
88+
/**
89+
* Write a value to the collector.
90+
*
91+
* @param value the value to be written
92+
*/
5993
public void writeValue(T value) {
6094
writeCollector.prepareWrite(1);
6195
writeCollector.queueValue(value);
6296
writeCollector.sendWriteRequest(0, recorder);
6397
}
64-
98+
99+
/**
100+
* The recorder that gives access to all the accumulated events.
101+
*
102+
* @return the event log
103+
*/
65104
public PVEventRecorder getRecorder() {
66105
return recorder;
67106
}
68-
107+
108+
/**
109+
* Creates a simple probe collector that does not write a log.
110+
*
111+
* @return a probe collector
112+
*/
69113
public static ProbeCollector<?> create() {
70114
return new ProbeCollector<>(Object.class, null);
71115
}

0 commit comments

Comments
 (0)