Skip to content

Commit 425ed23

Browse files
committed
make unit tests pass in CI
1 parent d6a22c5 commit 425ed23

File tree

11 files changed

+144
-76
lines changed

11 files changed

+144
-76
lines changed

build.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,9 @@ dependencies {
161161
api group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.6'
162162

163163
api group: 'org.reactfx', name: 'reactfx', version: '2.0-SNAPSHOT'
164-
165-
// https://mvnrepository.com/artifact/org.apache.groovy/groovy
164+
166165
api group: 'org.apache.groovy', name: 'groovy', version: '4.0.22'
167-
//make grapes work
168-
api group: 'org.apache.ivy', name: 'ivy', version: '2.5.1'
166+
api group: 'org.apache.ivy', name: 'ivy', version: '2.5.2'
169167

170168
//compile group: 'org.controlsfx', name: 'controlsfx', version: '8.0.6'
171169
api group: 'commons-lang', name: 'commons-lang', version: '2.6'
@@ -218,44 +216,48 @@ dependencies {
218216
exclude group: 'commons-io', module: 'commons-io'
219217
exclude group: 'com.twmacinta', module: 'fast-md5'
220218
exclude group: 'gov.nist.math', module: 'Jampack'
219+
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
221220
}
222221

223222
implementation('de.dfki.mary:voice-dfki-prudence-hsmm:5.2') {
224223
exclude group: 'commons-io', module: 'commons-io'
225224
exclude group: 'com.twmacinta', module: 'fast-md5'
226225
exclude group: 'gov.nist.math', module: 'Jampack'
226+
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
227227
}
228228
implementation('de.dfki.mary:voice-dfki-spike-hsmm:5.2') {
229229
exclude group: 'commons-io', module: 'commons-io'
230230
exclude group: 'com.twmacinta', module: 'fast-md5'
231231
exclude group: 'gov.nist.math', module: 'Jampack'
232+
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
232233
}
233234
implementation('de.dfki.mary:voice-cmu-rms-hsmm:5.2') {
234235
exclude group: 'commons-io', module: 'commons-io'
235-
236+
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
236237
exclude group: 'com.twmacinta', module: 'fast-md5'
237238
exclude group: 'gov.nist.math', module: 'Jampack'
238239
}
239240
implementation('de.dfki.mary:voice-dfki-obadiah-hsmm:5.2') {
240241
exclude group: 'commons-io', module: 'commons-io'
241-
242+
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
242243
exclude group: 'com.twmacinta', module: 'fast-md5'
243244
exclude group: 'gov.nist.math', module: 'Jampack'
244245
}
245246
implementation('de.dfki.mary:voice-cmu-rms-hsmm:5.2') {
246247
exclude group: 'commons-io', module: 'commons-io'
247-
248+
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
248249
exclude group: 'com.twmacinta', module: 'fast-md5'
249250
exclude group: 'gov.nist.math', module: 'Jampack'
250251
}
251252
implementation('de.dfki.mary:voice-cmu-bdl-hsmm:5.2') {
252253
exclude group: 'commons-io', module: 'commons-io'
253-
254+
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
254255
exclude group: 'com.twmacinta', module: 'fast-md5'
255256
exclude group: 'gov.nist.math', module: 'Jampack'
256257
}
257258
implementation('de.dfki.mary:marytts-lang-en:5.2.1') {
258259
exclude group: 'commons-io', module: 'commons-io'
260+
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
259261
exclude group: 'com.twmacinta', module: 'fast-md5'
260262
exclude group: 'gov.nist.math', module: 'Jampack'
261263
}

src/main/java/com/neuronrobotics/bowlerkernel/djl/PredictorFactory.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashMap;
66

77
import ai.djl.MalformedModelException;
8+
import ai.djl.ModelException;
89
import ai.djl.engine.Engine;
910
import ai.djl.inference.Predictor;
1011
import ai.djl.modality.cv.Image;
@@ -76,10 +77,20 @@ public static Predictor<Image, DetectedObjects> imageContentsFactory(ImagePredic
7677
String MODEL_URL = "https://mlrepo.djl.ai/model/cv/object_detection/ai/djl/onnxruntime/yolo5s/0.0.1/yolov5s.zip";
7778

7879
Criteria<Image, DetectedObjects> criteria2 = Criteria.builder()
79-
.setTypes(Image.class, DetectedObjects.class).optModelUrls(MODEL_URL)
80-
.optEngine("OnnxRuntime")
80+
.setTypes(Image.class, DetectedObjects.class).optModelUrls(MODEL_URL).optEngine("OnnxRuntime")
8181
.optTranslatorFactory(new YoloV5TranslatorFactory()).build();
82-
preloaded.put(type, criteria2.loadModel().newPredictor());
82+
83+
try {
84+
YoloManager ym = new YoloManager(criteria2);
85+
preloaded.put(type,ym.predictor());
86+
87+
} catch (IOException e) {
88+
// TODO Auto-generated catch block
89+
e.printStackTrace();
90+
} catch (ModelException e) {
91+
// TODO Auto-generated catch block
92+
e.printStackTrace();
93+
}
8394
break;
8495
default:
8596
throw new RuntimeException("No Model availible of type " + type);
@@ -105,12 +116,13 @@ public static Predictor<Image, float[]> faceFeatureFactory()
105116
}
106117
return features;
107118
}
119+
108120
public static float calculSimilarFaceFeature(float[] feature1, ArrayList<float[]> people) {
109121
float ret = 0.0f;
110122
float mod1 = 0.0f;
111123
float mod2 = 0.0f;
112124
int length = feature1.length;
113-
for(int j=0;j<people.size();j++) {
125+
for (int j = 0; j < people.size(); j++) {
114126
float[] feature2 = people.get(j);
115127
for (int i = 0; i < length; ++i) {
116128
ret += feature1[i] * feature2[i];
@@ -120,6 +132,7 @@ public static float calculSimilarFaceFeature(float[] feature1, ArrayList<float[]
120132
}
121133
return (float) ((ret / Math.sqrt(mod1) / Math.sqrt(mod2) + 1) / 2.0f);
122134
}
135+
123136
public static float calculSimilarFaceFeature(float[] feature1, float[] feature2) {
124137
float ret = 0.0f;
125138
float mod1 = 0.0f;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.neuronrobotics.bowlerkernel.djl;
2+
3+
import java.io.IOException;
4+
5+
import ai.djl.Model;
6+
import ai.djl.ModelException;
7+
import ai.djl.inference.Predictor;
8+
import ai.djl.modality.cv.Image;
9+
import ai.djl.modality.cv.output.DetectedObjects;
10+
import ai.djl.repository.zoo.Criteria;
11+
import ai.djl.repository.zoo.ZooModel;
12+
13+
public final class YoloManager implements AutoCloseable {
14+
private final ZooModel<Image, DetectedObjects> model;
15+
private final Predictor<Image, DetectedObjects> predictor;
16+
17+
public YoloManager(Criteria<Image, DetectedObjects> criteria) throws IOException, ModelException {
18+
this.model = criteria.loadModel();
19+
this.predictor = model.newPredictor();
20+
}
21+
22+
public Predictor<Image, DetectedObjects> predictor() {
23+
return predictor;
24+
}
25+
26+
@Override
27+
public void close() throws Exception {
28+
predictor.close(); // FIRST
29+
model.close(); // SECOND
30+
}
31+
}

src/main/java/com/neuronrobotics/bowlerstudio/physics/PhysicsEngine.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,8 @@
11
package com.neuronrobotics.bowlerstudio.physics;
22

3-
import java.io.File;
4-
import java.io.IOException;
53
import java.util.ArrayList;
64

7-
import javax.vecmath.Matrix4f;
8-
import javax.vecmath.Quat4f;
9-
import javax.vecmath.Vector3f;
10-
11-
import org.codehaus.groovy.transform.tailrec.TailRecursiveASTTransformation;
12-
import org.eclipse.jgit.api.errors.GitAPIException;
13-
import org.eclipse.jgit.api.errors.InvalidRemoteException;
14-
import org.eclipse.jgit.api.errors.TransportException;
15-
16-
import com.bulletphysics.collision.broadphase.BroadphaseInterface;
17-
import com.bulletphysics.collision.broadphase.DbvtBroadphase;
18-
import com.bulletphysics.collision.dispatch.CollisionDispatcher;
19-
import com.bulletphysics.collision.dispatch.DefaultCollisionConfiguration;
20-
import com.bulletphysics.collision.shapes.CollisionShape;
21-
import com.bulletphysics.collision.shapes.StaticPlaneShape;
22-
import com.bulletphysics.dynamics.DiscreteDynamicsWorld;
23-
import com.bulletphysics.dynamics.RigidBody;
24-
import com.bulletphysics.dynamics.RigidBodyConstructionInfo;
25-
import com.bulletphysics.dynamics.constraintsolver.SequentialImpulseConstraintSolver;
26-
import com.bulletphysics.linearmath.DefaultMotionState;
27-
import com.bulletphysics.linearmath.Transform;
28-
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
29-
import com.neuronrobotics.bowlerstudio.vitamins.Vitamins;
30-
import com.neuronrobotics.sdk.util.ThreadUtil;
31-
325
import eu.mihosoft.vrl.v3d.CSG;
33-
import eu.mihosoft.vrl.v3d.Sphere;
34-
35-
import javafx.application.Platform;
366

377
public class PhysicsEngine {
388

src/main/java/com/neuronrobotics/bowlerstudio/scripting/GroovyHelper.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,17 @@
55
import groovy.lang.Script;
66

77
import java.io.File;
8-
import java.io.IOException;
98
import java.io.InputStream;
109
import java.util.ArrayList;
1110
import java.util.Arrays;
1211

1312
import org.apache.commons.io.FileUtils;
1413
import org.apache.commons.io.IOUtils;
15-
import org.codehaus.groovy.control.CompilationFailedException;
1614
import org.codehaus.groovy.control.CompilerConfiguration;
1715
import org.codehaus.groovy.control.customizers.*;
1816

19-
import com.neuronrobotics.bowlerstudio.creature.MobileBaseCadManager;
20-
import com.neuronrobotics.bowlerstudio.creature.MobileBaseLoader;
21-
import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
22-
import com.neuronrobotics.sdk.common.DeviceManager;
2317
import com.neuronrobotics.sdk.common.Log;
2418

25-
import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase;
2619
import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance;
2720

2821
public class GroovyHelper implements IScriptingLanguage, IScriptingLanguageDebugger {

test/java/src/junit/bowler/CaDoodleWorkflowTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public void test() throws Exception {
9999
//com.neuronrobotics.sdk.common.Log.error(jsonContent);
100100
cf.save();
101101
File self = cf.getSelf();
102+
cf.close();
102103
if(!self.exists())
103104
fail("Doodle file does not exist, save failed! "+self.getAbsolutePath());
104105
CaDoodleFile loaded = CaDoodleFile.fromFile(self);
@@ -237,6 +238,7 @@ public void test() throws Exception {
237238
loaded.save();
238239

239240
String before = loaded.toJson();
241+
loaded.close();
240242
loaded=CaDoodleFile.fromJsonString(before);
241243
String after =loaded.toJson();
242244
if(!before.contentEquals(after))
@@ -289,6 +291,7 @@ public void test() throws Exception {
289291
}
290292
System.out.println("Saving");
291293
loaded.save();
294+
loaded.close();
292295
System.out.println("Save finished");
293296
}
294297

test/java/src/junit/bowler/GitHub.java

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
import java.util.List;
88
import java.util.Map;
99
import java.util.Set;
10+
import java.util.concurrent.CountDownLatch;
11+
import java.util.concurrent.TimeUnit;
1012

1113
import org.eclipse.jgit.api.errors.GitAPIException;
1214
import org.eclipse.jgit.api.errors.InvalidRemoteException;
1315
import org.eclipse.jgit.api.errors.TransportException;
1416
import org.eclipse.jgit.lib.Ref;
17+
import org.junit.AfterClass;
1518
import org.junit.Before;
1619
import org.junit.Test;
1720
import org.kohsuke.github.GHMyself;
@@ -22,15 +25,57 @@
2225

2326
import com.neuronrobotics.bowlerstudio.BowlerKernel;
2427
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
28+
import com.neuronrobotics.sdk.common.Log;
2529
import com.neuronrobotics.sdk.util.ThreadUtil;
2630

31+
import javafx.application.Platform;
32+
2733
public class GitHub {
28-
@Before
29-
public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception {
30-
BowlerKernel.startupProcedures();
31-
}
34+
private static boolean shutdownInProgress;
35+
@Before
36+
public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception {
37+
BowlerKernel.startupProcedures();
38+
}
39+
static {
40+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
41+
if (shutdownInProgress) return;
42+
shutdownInProgress = true;
43+
44+
Log.info("Beginning graceful shutdown...");
45+
46+
try {
47+
// 1. Stop JavaFX
48+
if ( isPlatformInitialized()&&Platform.isFxApplicationThread()) {
49+
Platform.exit();
50+
Thread.sleep(300);
51+
}
52+
53+
54+
// 3. Force GC
55+
System.gc();
56+
System.runFinalization();
57+
58+
// 4. Final wait
59+
Thread.sleep(500);
60+
61+
Log.info("Shutdown complete");
62+
} catch (Exception e) {
63+
Log.error( e);
64+
}
65+
}, "Shutdown-Hook"));
66+
}
67+
private static boolean isPlatformInitialized() {
68+
try {
69+
Platform.runLater(() -> {});
70+
return true;
71+
} catch (IllegalStateException e) {
72+
return false;
73+
}
74+
}
75+
3276
@Test
3377
public void test() throws Exception {
78+
com.neuronrobotics.sdk.common.Log.debug("Github Test disabled for CI");
3479
//ScriptingEngine.login();
3580
// String remoteURI = "https://github.com/madhephaestusdemo/WalkTest_madhephaestusdemo.git";
3681
// com.neuronrobotics.sdk.common.Log.error(ScriptingEngine.getRepositoryCloneDirectory(remoteURI));
@@ -127,5 +172,17 @@ public void test() throws Exception {
127172
com.neuronrobotics.sdk.common.Log.error("Current Branch # " + ScriptingEngine.getFullBranch(asstsRepo));
128173
*/
129174
}
175+
@AfterClass
176+
public static void tearDownJavaFX() throws InterruptedException {
177+
CountDownLatch latch = new CountDownLatch(1);
178+
Platform.runLater(() -> {
179+
Platform.exit();
180+
latch.countDown();
181+
});
182+
latch.await(5, TimeUnit.SECONDS);
183+
184+
// Give time for cleanup
185+
Thread.sleep(1000);
186+
}
130187

131188
}

test/java/src/junit/bowler/JsonTester.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import javafx.scene.control.MenuItem;
2020

2121
public class JsonTester {
22-
@Before
23-
public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception {
24-
BowlerKernel.startupProcedures();
25-
}
22+
2623
@Test
2724
public void test() throws Exception {
2825
/*

test/java/src/junit/bowler/MuJoCoBowlerIntegrationTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase;
2828
@SuppressWarnings("unchecked")
2929
public class MuJoCoBowlerIntegrationTest {
30-
@Before
31-
public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception {
32-
BowlerKernel.startupProcedures();
33-
}
30+
3431
@Test
3532
@Ignore
3633
public void test() throws Exception {

test/java/src/junit/bowler/MuJoCoTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@
88
import org.eclipse.jgit.api.errors.InvalidRemoteException;
99
import org.eclipse.jgit.api.errors.TransportException;
1010
import org.junit.Before;
11+
import org.junit.Ignore;
1112
import org.junit.Test;
1213
import org.mujoco.MuJoCoLib;
1314

1415
import com.neuronrobotics.bowlerstudio.BowlerKernel;
1516

1617
public class MuJoCoTest {
17-
@Before
18-
public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception {
19-
BowlerKernel.startupProcedures();
20-
}
18+
2119
@Test
2220
public void test() {
2321
com.neuronrobotics.sdk.common.Log.error("mujocoJNILoadTest");
2422
System.setProperty("org.bytedeco.javacpp.logger.debug", "true");
2523
MuJoCoLib lib = new MuJoCoLib();
2624

2725
com.neuronrobotics.sdk.common.Log.error("Starting " + MuJoCoLib.mj_versionString().getString());
26+
2827
}
2928

3029
}

0 commit comments

Comments
 (0)