Skip to content

Commit 3d58130

Browse files
committed
fix bogus test
1 parent ba8270e commit 3d58130

File tree

3 files changed

+316
-329
lines changed

3 files changed

+316
-329
lines changed

src/test/java/TestClient.java

+107-113
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2015 Ekumen www.ekumenlabs.com
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,135 +15,129 @@
1515
*/
1616

1717

18-
19-
import java.util.List;
20-
import org.ros.namespace.GraphName;
21-
import org.ros.node.AbstractNodeMain;
22-
import org.ros.node.ConnectedNode;
23-
import org.ros.message.Duration;
24-
import actionlib_tutorials.FibonacciActionGoal;
25-
import actionlib_tutorials.FibonacciActionFeedback;
26-
import actionlib_tutorials.FibonacciActionResult;
27-
import actionlib_tutorials.FibonacciGoal;
28-
import actionlib_tutorials.FibonacciFeedback;
29-
import actionlib_tutorials.FibonacciResult;
30-
import actionlib_msgs.GoalStatusArray;
3118
import actionlib_msgs.GoalID;
3219
import actionlib_msgs.GoalStatus;
20+
import actionlib_msgs.GoalStatusArray;
21+
import actionlib_tutorials.*;
3322
import com.github.rosjava_actionlib.ActionClient;
3423
import com.github.rosjava_actionlib.ActionClientListener;
3524
import com.github.rosjava_actionlib.ClientStateMachine;
3625
import org.apache.commons.logging.Log;
26+
import org.ros.message.Duration;
27+
import org.ros.namespace.GraphName;
28+
import org.ros.node.AbstractNodeMain;
29+
import org.ros.node.ConnectedNode;
30+
31+
import java.util.List;
3732

3833

3934
/**
4035
* Class to test the actionlib client.
4136
* @author Ernesto Corbellini [email protected]
4237
*/
4338
public class TestClient extends AbstractNodeMain implements ActionClientListener<FibonacciActionFeedback, FibonacciActionResult> {
44-
static {
45-
// comment this line if you want logs activated
46-
System.setProperty("org.apache.commons.logging.Log",
47-
"org.apache.commons.logging.impl.NoOpLog");
48-
}
49-
private ActionClient ac = null;
50-
private volatile boolean resultReceived = false;
51-
private Log log;
52-
53-
@Override
54-
public GraphName getDefaultNodeName() {
55-
return GraphName.of("fibonacci_test_client");
56-
}
57-
58-
@Override
59-
public void onStart(ConnectedNode node) {
60-
ac = new ActionClient<FibonacciActionGoal, FibonacciActionFeedback, FibonacciActionResult>(node, "/fibonacci", FibonacciActionGoal._TYPE, FibonacciActionFeedback._TYPE, FibonacciActionResult._TYPE);
61-
FibonacciActionGoal goalMessage;
62-
GoalID gid;
63-
Duration serverTimeout = new Duration(20);
64-
boolean serverStarted;
65-
66-
log = node.getLog();
67-
// Attach listener for the callbacks
68-
ac.attachListener(this);
69-
System.out.println("\nWaiting for action server to start...");
70-
serverStarted = ac.waitForActionServerToStart(new Duration(20));
71-
if (serverStarted) {
72-
System.out.println("Action server started.\n");
39+
static {
40+
// comment this line if you want logs activated
41+
System.setProperty("org.apache.commons.logging.Log",
42+
"org.apache.commons.logging.impl.NoOpLog");
7343
}
74-
else {
75-
System.out.println("No actionlib server found after waiting for " + serverTimeout.totalNsecs()/1e9 + " seconds!");
76-
System.exit(1);
44+
45+
private ActionClient ac = null;
46+
private volatile boolean resultReceived = false;
47+
private Log log;
48+
49+
@Override
50+
public GraphName getDefaultNodeName() {
51+
return GraphName.of("fibonacci_test_client");
7752
}
7853

79-
// Create Fibonacci goal message
80-
goalMessage = (FibonacciActionGoal)ac.newGoalMessage();
81-
FibonacciGoal fibonacciGoal = goalMessage.getGoal();
82-
// set Fibonacci parameter
83-
fibonacciGoal.setOrder(3);
84-
System.out.println("Sending goal...");
85-
ac.sendGoal(goalMessage);
86-
gid = ac.getGoalId(goalMessage);
87-
System.out.println("Sent goal with ID: " + gid.getId());
88-
System.out.println("Waiting for goal to complete...");
89-
while (ac.getGoalState() != ClientStateMachine.ClientStates.DONE) {
90-
sleep(1);
54+
@Override
55+
public void onStart(ConnectedNode node) {
56+
ac = new ActionClient<FibonacciActionGoal, FibonacciActionFeedback, FibonacciActionResult>(node, "/fibonacci", FibonacciActionGoal._TYPE, FibonacciActionFeedback._TYPE, FibonacciActionResult._TYPE);
57+
FibonacciActionGoal goalMessage;
58+
GoalID gid;
59+
Duration serverTimeout = new Duration(20);
60+
boolean serverStarted;
61+
62+
log = node.getLog();
63+
// Attach listener for the callbacks
64+
ac.attachListener(this);
65+
System.out.println("\nWaiting for action server to start...");
66+
serverStarted = ac.waitForActionServerToStart(new Duration(20));
67+
if (serverStarted) {
68+
System.out.println("Action server started.\n");
69+
} else {
70+
System.out.println("No actionlib server found after waiting for " + serverTimeout.totalNsecs() / 1e9 + " seconds!");
71+
System.exit(1);
72+
}
73+
74+
// Create Fibonacci goal message
75+
goalMessage = (FibonacciActionGoal) ac.newGoalMessage();
76+
FibonacciGoal fibonacciGoal = goalMessage.getGoal();
77+
// set Fibonacci parameter
78+
fibonacciGoal.setOrder(3);
79+
System.out.println("Sending goal...");
80+
ac.sendGoal(goalMessage);
81+
gid = ac.getGoalId(goalMessage);
82+
System.out.println("Sent goal with ID: " + gid.getId());
83+
System.out.println("Waiting for goal to complete...");
84+
while (ac.getGoalState() != ClientStateMachine.ClientStates.DONE) {
85+
sleep(1);
86+
}
87+
System.out.println("Goal completed!\n");
88+
89+
System.out.println("Sending a new goal...");
90+
ac.sendGoal(goalMessage);
91+
gid = ac.getGoalId(goalMessage);
92+
System.out.println("Sent goal with ID: " + gid.getId());
93+
System.out.println("Cancelling this goal...");
94+
ac.sendCancel(gid);
95+
while (ac.getGoalState() != ClientStateMachine.ClientStates.DONE) {
96+
sleep(1);
97+
}
98+
System.out.println("Goal cancelled succesfully.\n");
99+
System.out.println("Bye!");
100+
System.exit(0);
91101
}
92-
System.out.println("Goal completed!\n");
93-
94-
System.out.println("Sending a new goal...");
95-
ac.sendGoal(goalMessage);
96-
gid = ac.getGoalId(goalMessage);
97-
System.out.println("Sent goal with ID: " + gid.getId());
98-
System.out.println("Cancelling this goal...");
99-
ac.sendCancel(gid);
100-
while (ac.getGoalState() != ClientStateMachine.ClientStates.DONE) {
101-
sleep(1);
102+
103+
@Override
104+
public void resultReceived(FibonacciActionResult message) {
105+
FibonacciResult result = message.getResult();
106+
int[] sequence = result.getSequence();
107+
int i;
108+
109+
resultReceived = true;
110+
System.out.print("Got Fibonacci result sequence: ");
111+
for (i = 0; i < sequence.length; i++)
112+
System.out.print(Integer.toString(sequence[i]) + " ");
113+
System.out.println("");
102114
}
103-
System.out.println("Goal cancelled succesfully.\n");
104-
System.out.println("Bye!");
105-
System.exit(0);
106-
}
107-
108-
@Override
109-
public void resultReceived(FibonacciActionResult message) {
110-
FibonacciResult result = message.getResult();
111-
int[] sequence = result.getSequence();
112-
int i;
113-
114-
resultReceived = true;
115-
System.out.print("Got Fibonacci result sequence: ");
116-
for (i=0; i<sequence.length; i++)
117-
System.out.print(Integer.toString(sequence[i]) + " ");
118-
System.out.println("");
119-
}
120-
121-
@Override
122-
public void feedbackReceived(FibonacciActionFeedback message) {
123-
FibonacciFeedback result = message.getFeedback();
124-
int[] sequence = result.getSequence();
125-
int i;
126-
127-
System.out.print("Feedback from Fibonacci server: ");
128-
for (i=0; i<sequence.length; i++)
129-
System.out.print(Integer.toString(sequence[i]) + " ");
130-
System.out.print("\n");
131-
}
132-
133-
@Override
134-
public void statusReceived(GoalStatusArray status) {
135-
List<GoalStatus> statusList = status.getStatusList();
136-
for(GoalStatus gs:statusList) {
137-
log.info("GoalID: " + gs.getGoalId().getId() + " -- GoalStatus: " + gs.getStatus() + " -- " + gs.getText());
115+
116+
@Override
117+
public void feedbackReceived(FibonacciActionFeedback message) {
118+
FibonacciFeedback result = message.getFeedback();
119+
int[] sequence = result.getSequence();
120+
int i;
121+
122+
System.out.print("Feedback from Fibonacci server: ");
123+
for (i = 0; i < sequence.length; i++)
124+
System.out.print(Integer.toString(sequence[i]) + " ");
125+
System.out.print("\n");
138126
}
139-
log.info("Current state of our goal: " + ClientStateMachine.ClientStates.translateState(ac.getGoalState()));
140-
}
141127

142-
void sleep(long msec) {
143-
try {
144-
Thread.sleep(msec);
128+
@Override
129+
public void statusReceived(GoalStatusArray status) {
130+
List<GoalStatus> statusList = status.getStatusList();
131+
for (GoalStatus gs : statusList) {
132+
log.info("GoalID: " + gs.getGoalId().getId() + " -- GoalStatus: " + gs.getStatus() + " -- " + gs.getText());
133+
}
134+
log.info("Current state of our goal: " + ClientStateMachine.ClientStates.translateState(ac.getGoalState()));
145135
}
146-
catch (InterruptedException ex) {
136+
137+
void sleep(long msec) {
138+
try {
139+
Thread.sleep(msec);
140+
} catch (InterruptedException ex) {
141+
}
147142
}
148-
}
149143
}

0 commit comments

Comments
 (0)