1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.scripting.xmltags;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19 import static org.junit.jupiter.api.Assertions.assertNotNull;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.Executors;
27 import java.util.concurrent.Future;
28 import java.util.stream.IntStream;
29
30 import org.junit.jupiter.api.Test;
31
32 class OgnlCacheTest {
33 @Test
34 void concurrentAccess() throws Exception {
35 class DataClass {
36 @SuppressWarnings("unused")
37 private int id;
38 }
39 int run = 1000;
40 Map<String, Object> context = new HashMap<>();
41 List<Future<Object>> futures = new ArrayList<>();
42 context.put("data", new DataClass());
43 ExecutorService executor = Executors.newCachedThreadPool();
44 IntStream.range(0, run).forEach(i -> {
45 futures.add(executor.submit(() -> OgnlCache.getValue("data.id", context)));
46 });
47 for (int i = 0; i < run; i++) {
48 assertNotNull(futures.get(i).get());
49 }
50 executor.shutdown();
51 }
52
53 @Test
54 void issue2609() throws Exception {
55 Map<String, Object> context = new HashMap<>();
56 context.put("d1", java.sql.Date.valueOf("2022-01-01"));
57 context.put("d2", java.sql.Date.valueOf("2022-01-02"));
58 assertEquals(-1, OgnlCache.getValue("d1.compareTo(d2)", context));
59 }
60 }