-
Notifications
You must be signed in to change notification settings - Fork 9
/
MultidatabaseTest.java
120 lines (87 loc) · 3.85 KB
/
MultidatabaseTest.java
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
117
118
119
120
/*
Copyright 2022 CodeNotary, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.codenotary.immudb4j;
import io.codenotary.immudb4j.exceptions.CorruptedDataException;
import io.codenotary.immudb4j.exceptions.VerificationException;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.List;
public class MultidatabaseTest extends ImmuClientIntegrationTest {
@Test(testName = "createDatabase without open session", expectedExceptions = IllegalStateException.class)
public void t1() {
immuClient.createDatabase("db1");
}
@Test(testName = "loadDatabase without open session", expectedExceptions = IllegalStateException.class)
public void t2() {
immuClient.loadDatabase("db1");
}
@Test(testName = "unloadDatabase without open session", expectedExceptions = IllegalStateException.class)
public void t3() {
immuClient.unloadDatabase("db1");
}
@Test(testName = "deleteDatabase without open session", expectedExceptions = IllegalStateException.class)
public void t4() {
immuClient.deleteDatabase("db1");
}
@Test(testName = "Interacting with multiple databases (creating them, setting, and getting, listing)")
public void t5() throws VerificationException {
immuClient.openSession("defaultdb", "immudb", "immudb");
immuClient.createDatabase("db1", true);
immuClient.createDatabase("db2", true);
immuClient.closeSession();
immuClient.openSession("db1", "immudb", "immudb");
byte[] v0 = new byte[] { 0, 1, 2, 3 };
try {
immuClient.set("k0", v0);
} catch (CorruptedDataException e) {
Assert.fail("Failed at set.", e);
}
immuClient.closeSession();
immuClient.openSession("db2", "immudb", "immudb");
byte[] v1 = new byte[] { 3, 2, 1, 0 };
try {
immuClient.set("k1", v1);
} catch (CorruptedDataException e) {
Assert.fail("Failed at set.", e);
}
immuClient.closeSession();
immuClient.openSession("db1", "immudb", "immudb");
Entry entry1 = immuClient.get("k0");
Assert.assertNotNull(entry1);
Assert.assertEquals(entry1.getValue(), v0);
Entry ventry1 = immuClient.verifiedGet("k0");
Assert.assertNotNull(ventry1);
Assert.assertEquals(ventry1.getValue(), v0);
immuClient.closeSession();
immuClient.openSession("db2", "immudb", "immudb");
Entry entry2 = immuClient.get("k1");
Assert.assertEquals(entry2.getValue(), v1);
Entry ventry2 = immuClient.verifiedGet("k1");
Assert.assertEquals(ventry2.getValue(), v1);
List<String> dbs = immuClient.databases();
Assert.assertNotNull(dbs);
Assert.assertEquals(3, dbs.size(), String.format("Expected 3, but got %d dbs: %s", dbs.size(), dbs));
Assert.assertTrue(dbs.contains("defaultdb"));
Assert.assertTrue(dbs.contains("db1"));
Assert.assertTrue(dbs.contains("db2"));
immuClient.closeSession();
}
@Test(testName = "create, unload and delete database")
public void t6() {
immuClient.openSession("defaultdb", "immudb", "immudb");
immuClient.createDatabase("manageddb");
immuClient.unloadDatabase("manageddb");
immuClient.deleteDatabase("manageddb");
immuClient.closeSession();
}
}