1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.config.store;
18
19 import static org.junit.jupiter.api.Assertions.*;
20
21 import java.util.concurrent.*;
22
23 import org.apache.juneau.*;
24 import org.junit.jupiter.api.*;
25
26 class ConfigMemoryStore_Test extends TestBase {
27
28 @Test void a01_noFile() {
29 var fs = MemoryStore.create().build();
30 assertEquals("", fs.read("X"));
31 }
32
33 @Test void a02_simpleCreate() {
34 var fs = MemoryStore.create().build();
35 assertNull(fs.write("X", null, "foo"));
36 assertEquals("foo", fs.read("X"));
37 }
38
39 @Test void a03_failOnMismatch() {
40 var fs = MemoryStore.create().build();
41 assertNotNull(fs.write("X", "xxx", "foo"));
42 assertEquals("", fs.read("X"));
43 assertNull(fs.write("X", null, "foo"));
44 assertEquals("foo", fs.read("X"));
45 assertNotNull(fs.write("X", "xxx", "foo"));
46 assertEquals("foo", fs.read("X"));
47 assertNull(fs.write("X", "foo", "bar"));
48 assertEquals("bar", fs.read("X"));
49 }
50
51 @Test void a04_update() throws Exception {
52 var fs = MemoryStore.create().build();
53
54 final var latch = new CountDownLatch(2);
55 fs.register("X", contents -> {
56 if ("xxx".equals(contents))
57 latch.countDown();
58 });
59 fs.register("Y", contents -> {
60 if ("yyy".equals(contents))
61 latch.countDown();
62 });
63
64 fs.update("X", "xxx");
65 assertDoesNotThrow(()->fs.update("Y", "yyy"));
66 if (! latch.await(10, TimeUnit.SECONDS))
67 throw new Exception("CountDownLatch never reached zero.");
68 }
69
70 @Test void a05_exists() {
71 MemoryStore.DEFAULT.write("foo", null, "foo");
72
73 assertTrue(MemoryStore.DEFAULT.exists("foo"));
74 assertFalse(MemoryStore.DEFAULT.exists("foo2"));
75
76 MemoryStore.DEFAULT.write("foo", "foo", null);
77
78 assertFalse(MemoryStore.DEFAULT.exists("foo"));
79 assertFalse(MemoryStore.DEFAULT.exists("foo2"));
80 }
81 }