Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
119 lines (106 loc) · 3.5 KB

File metadata and controls

119 lines (106 loc) · 3.5 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* Copyright © 2016-2025 The LmdbJava Open Source Project
*
* 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 org.lmdbjava;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.lmdbjava.Env.create;
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
import static org.lmdbjava.TxnFlags.MDB_RDONLY_TXN;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.lmdbjava.Env.AlreadyClosedException;
import org.lmdbjava.Txn.IncompatibleParent;
/**
* Tests all the deprecated txn related methods in {@link Env}. Essentially a duplicate of {@link
* TxnTest}. When all the deprecated methods are deleted we can delete this test class.
*
* @deprecated Tests all the deprecated txn related methods in {@link Env}.
*/
@Deprecated
public final class TxnDeprecatedTest {
private Path file;
private Env<ByteBuffer> env;
private TempDir tempDir;
@BeforeEach
void beforeEach() {
tempDir = new TempDir();
file = tempDir.createTempFile();
env =
create()
.setMapSize(256, ByteUnit.KIBIBYTES)
.setMaxReaders(1)
.setMaxDbs(2)
.setEnvFlags(MDB_NOSUBDIR)
.open(file);
}
@AfterEach
void afterEach() {
env.close();
tempDir.cleanup();
}
@Test
public void txParent() {
try (Txn<ByteBuffer> txRoot = env.txnWrite();
Txn<ByteBuffer> txChild = env.txn(txRoot, new TxnFlags[0])) {
assertThat(txRoot.getParent()).isNull();
assertThat(txChild.getParent()).isEqualTo(txRoot);
}
}
@Test
public void txParent2() {
try (Txn<ByteBuffer> txRoot = env.txnWrite();
Txn<ByteBuffer> txChild = env.txn(txRoot, (TxnFlags[]) null)) {
assertThat(txRoot.getParent()).isNull();
assertThat(txChild.getParent()).isEqualTo(txRoot);
}
}
@Test
void txParentDeniedIfEnvClosed() {
assertThatThrownBy(
() -> {
try (Txn<ByteBuffer> txRoot = env.txnWrite();
Txn<ByteBuffer> txChild = env.txn(txRoot, new TxnFlags[0])) {
env.close();
assertThat(txChild.getParent()).isEqualTo(txRoot);
}
})
.isInstanceOf(AlreadyClosedException.class);
}
@Test
void txParentROChildRWIncompatible() {
assertThatThrownBy(
() -> {
try (Txn<ByteBuffer> txRoot = env.txnRead()) {
env.txn(txRoot, new TxnFlags[0]); // error
}
})
.isInstanceOf(IncompatibleParent.class);
}
@Test
void txParentRWChildROIncompatible() {
assertThatThrownBy(
() -> {
try (Txn<ByteBuffer> txRoot = env.txnWrite()) {
TxnFlags[] flags = new TxnFlags[] {MDB_RDONLY_TXN};
env.txn(txRoot, flags); // error
}
})
.isInstanceOf(IncompatibleParent.class);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.