Skip to content

Commit 6a48dd3

Browse files
committed
add new tests for ConcurrentObjectDictionary
1 parent 97c6432 commit 6a48dd3

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

rlib-common/src/test/java/com/ss/rlib/common/test/util/dictionary/ConcurrentObjectDictionaryTest.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,68 @@ void runInReadLockTest() {
5959
dic.get(arg);
6060
});
6161
}
62+
63+
@Test
64+
void getInWriteLockTest() {
65+
66+
var dictionary = ConcurrentObjectDictionary.ofType(
67+
String.class,
68+
Integer.class
69+
);
70+
71+
dictionary.runInWriteLock(dic -> {
72+
dic.put("1", 1);
73+
dic.put("2", 2);
74+
dic.put("3", 3);
75+
});
76+
77+
Integer val1 = dictionary.getInWriteLock("1", (dic, arg) -> {
78+
assertType(dic, ConcurrentObjectDictionary.class);
79+
assertType(arg, String.class);
80+
return dic.get(arg);
81+
});
82+
83+
Assertions.assertEquals(1, val1);
84+
85+
Integer val2 = dictionary.getInWriteLock("2", Type1.EXAMPLE, (dic, arg1, arg2) -> {
86+
assertType(dic, ConcurrentObjectDictionary.class);
87+
assertType(arg1, String.class);
88+
assertType(arg2, Type1.class);
89+
return dic.get(arg1);
90+
});
91+
92+
Assertions.assertEquals(2, val2);
93+
}
94+
95+
@Test
96+
void getInReadLockTest() {
97+
98+
var dictionary = ConcurrentObjectDictionary.ofType(
99+
String.class,
100+
Integer.class
101+
);
102+
103+
dictionary.runInWriteLock(dic -> {
104+
dic.put("1", 1);
105+
dic.put("2", 2);
106+
dic.put("3", 3);
107+
});
108+
109+
Integer val1 = dictionary.getInReadLock("1", (dic, arg) -> {
110+
assertType(dic, ConcurrentObjectDictionary.class);
111+
assertType(arg, String.class);
112+
return dic.get(arg);
113+
});
114+
115+
Assertions.assertEquals(1, val1);
116+
117+
Integer val2 = dictionary.getInReadLock("2", Type1.EXAMPLE, (dic, arg1, arg2) -> {
118+
assertType(dic, ConcurrentObjectDictionary.class);
119+
assertType(arg1, String.class);
120+
assertType(arg2, Type1.class);
121+
return dic.get(arg1);
122+
});
123+
124+
Assertions.assertEquals(2, val2);
125+
}
62126
}

0 commit comments

Comments
 (0)