-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathVolatileTest.java
More file actions
111 lines (88 loc) · 3.36 KB
/
Copy pathVolatileTest.java
File metadata and controls
111 lines (88 loc) · 3.36 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
/*
* Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0
*/
package net.openhft.chronicle.values;
import net.openhft.chronicle.bytes.Byteable;
import net.openhft.chronicle.bytes.BytesStore;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer;
import static net.openhft.chronicle.values.Values.newHeapInstance;
import static net.openhft.chronicle.values.Values.newNativeReference;
import static org.junit.jupiter.api.Assertions.*;
/*
* Created by daniel on 11/06/2014.
*/
public class VolatileTest extends ValuesTestCommon {
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void testGenerateJavaCode() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
/* try{
BadInterface1 jbi = dvg.heapInstance(BadInterface1.class);
assertFalse(true, "Should have thrown an IllegalArgumentException");
}catch(AssertionError e){
assertTrue("Throws an IllegalArgumentException", true);
}
try{
BadInterface2 jbi = dvg.heapInstance(BadInterface2.class);
assertFalse(true, "Should have thrown an IllegalArgumentException");
}catch(AssertionError e){
assertTrue("Throws an IllegalArgumentException", true);
}
*/
//Test the heap interface
try {
GoodInterface jbi = newHeapInstance(GoodInterface.class);
jbi.setOrderedY(5);
assertEquals(5, jbi.getVolatileY());
jbi.setOrderedIntAt(0, 0);
jbi.setOrderedIntAt(1, 1);
jbi.setOrderedIntAt(2, 2);
jbi.setOrderedIntAt(3, 3);
assertEquals(0, jbi.getVolatileIntAt(0));
assertEquals(1, jbi.getVolatileIntAt(1));
assertEquals(2, jbi.getVolatileIntAt(2));
assertEquals(3, jbi.getVolatileIntAt(3));
} catch (AssertionError e) {
e.printStackTrace();
assertFalse(true, "Throws an IllegalArgumentException");
}
//Test the native interface
try {
GoodInterface jbi = newNativeReference(GoodInterface.class);
BytesStore<?, ByteBuffer> bytes = BytesStore.wrap(ByteBuffer.allocate(64));
((Byteable) jbi).bytesStore(bytes, 0L, ((Byteable) jbi).maxSize());
jbi.setOrderedY(5);
assertEquals(5, jbi.getVolatileY());
jbi.setOrderedIntAt(0, 0);
jbi.setOrderedIntAt(1, 1);
jbi.setOrderedIntAt(2, 2);
jbi.setOrderedIntAt(3, 3);
assertEquals(0, jbi.getVolatileIntAt(0));
assertEquals(1, jbi.getVolatileIntAt(1));
assertEquals(2, jbi.getVolatileIntAt(2));
assertEquals(3, jbi.getVolatileIntAt(3));
} catch (AssertionError e) {
e.printStackTrace();
assertFalse(true, "Throws an IllegalArgumentException");
}
}
public interface BadInterface1 {
int getX();
void setOrderedX(int x);
}
public interface BadInterface2 {
int getVolatileX();
void setX(int x);
}
public interface GoodInterface {
int getX();
void setX(int x);
int getVolatileY();
void setOrderedY(int y);
int getY();
void setY(int y);
@Array(length = 4)
void setOrderedIntAt(int idx, int i);
int getVolatileIntAt(int idx);
}
}