Skip to content

Commit cbf184e

Browse files
[temp] debug test
1 parent cd6e720 commit cbf184e

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

pkgs/jnigen/test/simple_package_test/java/com/github/dart_lang/jnigen/interfaces/StringConverterConsumer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
public class StringConverterConsumer {
1212
public static Integer consumeOnSameThread(StringConverter stringConverter, String s) {
13+
long id = Thread.currentThread().getId();
14+
System.out.println("J: Currently on " + id);
1315
try {
1416
return stringConverter.parseToInt(s);
1517
} catch (StringConversionException e) {
@@ -18,6 +20,8 @@ public static Integer consumeOnSameThread(StringConverter stringConverter, Strin
1820
}
1921

2022
public static Future<Integer> consumeOnAnotherThread(StringConverter stringConverter, String s) {
23+
long id = Thread.currentThread().getId();
24+
System.out.println("J again: Currently on " + id);
2125
ExecutorService executor = Executors.newSingleThreadExecutor();
2226
return executor.submit(() -> consumeOnSameThread(stringConverter, s));
2327
}

pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -710,17 +710,31 @@ void registerTests(String groupName, TestRunnerCallback test) {
710710

711711
// Gets the result of a Java Future.
712712
// TODO(#1213): remove this once we support Java futures.
713+
void printCurrentThreadId([String prefix = '']) {
714+
final threadClass = JClass.forName('java/lang/Thread');
715+
final currentThread = threadClass.staticMethodId(
716+
'currentThread', '()Ljava/lang/Thread;');
717+
final getId = threadClass.instanceMethodId('getId', '()J');
718+
final thread = currentThread(threadClass, JObject.type, []);
719+
final threadId = getId.call(thread, jlong.type, []);
720+
print('${prefix}Currently on $threadId');
721+
}
722+
713723
Future<$T> toDartFuture<$T extends JObject>(
714724
JObject future, JObjType<$T> T) {
715725
return Isolate.run(() {
726+
printCurrentThreadId('Dart Isolate: ');
727+
print('waiting for get');
716728
final futureClass = JClass.forName('java/util/concurrent/Future');
717729
final getMethod =
718730
futureClass.instanceMethodId('get', '()Ljava/lang/Object;');
719731
final result = getMethod(future, JObject.type, []);
732+
print('get finished');
720733
return result.castTo(T);
721734
});
722735
}
723736

737+
printCurrentThreadId('Dart main: ');
724738
final sevenHundredBoxed = consume(stringConverter, '700'.toJString());
725739
final int sevenHundred;
726740
if (sevenHundredBoxed is JInteger) {
@@ -732,14 +746,14 @@ void registerTests(String groupName, TestRunnerCallback test) {
732746
}
733747
expect(sevenHundred, 700);
734748

735-
final fooBoxed = consume(stringConverter, 'foo'.toJString());
736-
final int foo;
737-
if (fooBoxed is JInteger) {
738-
foo = fooBoxed.intValue();
739-
} else {
740-
foo = (await toDartFuture(fooBoxed, JInteger.type)).intValue();
741-
}
742-
expect(foo, -1);
749+
// final fooBoxed = consume(stringConverter, 'foo'.toJString());
750+
// final int foo;
751+
// if (fooBoxed is JInteger) {
752+
// foo = fooBoxed.intValue();
753+
// } else {
754+
// foo = (await toDartFuture(fooBoxed, JInteger.type)).intValue();
755+
// }
756+
// expect(foo, -1);
743757

744758
stringConverter.release();
745759
});

0 commit comments

Comments
 (0)