forked from tikv/client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetricsTest.java
More file actions
104 lines (90 loc) · 3.18 KB
/
MetricsTest.java
File metadata and controls
104 lines (90 loc) · 3.18 KB
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
/*
* Copyright 2021 TiKV Project Authors.
*
* 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.tikv.raw;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.junit.After;
import org.junit.Test;
import org.tikv.BaseRawKVTest;
import org.tikv.common.TiConfiguration;
import org.tikv.common.TiSession;
public class MetricsTest extends BaseRawKVTest {
private final List<TiSession> sessionList = new ArrayList<>();
@After
public void tearDown() throws Exception {
for (TiSession tiSession : sessionList) {
if (tiSession != null) {
tiSession.close();
}
}
}
@Test
public void oneTiSession() throws Exception {
TiConfiguration conf = createTiConfiguration();
conf.setMetricsEnable(true);
TiSession session = TiSession.create(conf);
sessionList.add(session);
RawKVClient client = session.createRawClient();
client.put(ByteString.copyFromUtf8("k"), ByteString.copyFromUtf8("v"));
Optional<ByteString> result = client.get(ByteString.copyFromUtf8("k"));
assertTrue(result.isPresent());
assertEquals("v", result.get().toStringUtf8());
client.close();
session.close();
}
@Test
public void twoTiSession() throws Exception {
TiConfiguration conf = createTiConfiguration();
conf.setMetricsEnable(true);
TiSession session1 = TiSession.create(conf);
sessionList.add(session1);
RawKVClient client1 = session1.createRawClient();
client1.put(ByteString.copyFromUtf8("k1"), ByteString.copyFromUtf8("v1"));
TiSession session2 = TiSession.create(conf);
sessionList.add(session2);
RawKVClient client2 = session2.createRawClient();
client2.put(ByteString.copyFromUtf8("k2"), ByteString.copyFromUtf8("v2"));
client1.close();
session1.close();
Optional<ByteString> result = client2.get(ByteString.copyFromUtf8("k2"));
assertTrue(result.isPresent());
assertEquals("v2", result.get().toStringUtf8());
client2.close();
session2.close();
}
@Test
public void twoTiSessionWithDifferentPort() {
TiConfiguration conf1 = createTiConfiguration();
conf1.setMetricsEnable(true);
conf1.setMetricsPort(12345);
TiSession session1 = TiSession.create(conf1);
sessionList.add(session1);
TiConfiguration conf2 = createTiConfiguration();
conf2.setMetricsEnable(true);
conf2.setMetricsPort(54321);
try {
TiSession.create(conf2);
} catch (IllegalArgumentException e) {
assertEquals(
"Do dot support multiple tikv.metrics.port, which are 54321 and 12345", e.getMessage());
}
}
}