-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathGCTestHelper.java
More file actions
116 lines (103 loc) · 3.81 KB
/
Copy pathGCTestHelper.java
File metadata and controls
116 lines (103 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package javatests;
import org.python.core.*;
import java.util.*;
public class GCTestHelper {
/**
* NastyFinalizer is a non-PyObject class with a time-consuming
* finalizer that does not notify Jython-gc. This would cause
* some tests in test_gc_jy.py to fail.
*/
public static class NastyFinalizer {
public void finalize() {
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
}
}
}
/**
* In contrast to NastyFinalizer, this class - still equally
* time-consuming - calls {@code gc.notifyPreFinalization()}
* and {@code gc.notifyPostFinalization()} and thus lets all
* tests work as expected.
*/
public static class NotSoNastyFinalizer {
public void finalize() {
org.python.modules.gc.notifyPreFinalization();
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
}
org.python.modules.gc.notifyPostFinalization();
}
}
/**
* PyReflectionTraversed is a test-PyObject that intentionally
* violates the Traverseproc-mechanism, i.e. holds a non-static
* reference to another PyObject, but neither implements Traverseproc
* nor is marked as untraversable.
*/
public static class PyReflectionTraversed extends PyObject {
PyObject referent1;
PyObject[] refArray = new PyObject[3];
List<Object> refList = new ArrayList<>();
PyObject referent2;
public PyReflectionTraversed() {
super();
}
}
public static PyObject reflectionTraverseTestField() {
PyReflectionTraversed result = new PyReflectionTraversed();
result.referent1 = new PyList();
result.refArray[0] = new PyInteger(244);
result.refArray[1] = new PyBytes("test1");
result.refArray[2] = new PyInteger(333);
result.refList.add(new PyFloat(0.7));
result.referent2 = result;
return result;
}
public static PyObject reflectionTraverseTestList() {
PyReflectionTraversed result = new PyReflectionTraversed();
result.referent1 = new PyList();
result.refArray[0] = new PyInteger(245);
result.refArray[1] = new PyBytes("test2");
result.refArray[2] = new PyInteger(334);
result.refList.add(new PyFloat(0.71));
result.refList.add(result);
return result;
}
public static PyObject reflectionTraverseTestArray() {
PyReflectionTraversed result = new PyReflectionTraversed();
result.referent1 = new PyList();
result.refArray[0] = new PyInteger(246);
result.refArray[1] = new PyBytes("test3");
result.refArray[2] = result;
result.refList.add(new PyFloat(0.72));
return result;
}
public static PyObject reflectionTraverseTestPyList() {
PyReflectionTraversed result = new PyReflectionTraversed();
result.referent1 = new PyList();
result.refArray[0] = new PyInteger(247);
result.refArray[1] = new PyBytes("test4");
result.refArray[2] = new PyInteger(335);
result.refList.add(new PyFloat(0.73));
result.refList.add(new PyFloat(-0.73));
PyList pl = new PyList();
result.referent2 = pl;
pl.add(Py.True);
pl.add(new PyBytes("test5"));
pl.add(result);
return result;
}
public static PyObject reflectionTraverseTestCycle() {
PyReflectionTraversed result = new PyReflectionTraversed();
result.referent1 = new PyList();
result.refArray[0] = new PyInteger(248);
result.refArray[1] = new PyBytes("test6");
result.refArray[2] = new PyInteger(336);
result.refList.add(new PyFloat(0.74));
result.refList.add(result.refList);
return result;
}
}