blob: 8a17fedee86fbe7b5c48905cf24660e8de7d16a1 (
plain) (
blame)
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core.hostinfo;
import com.yahoo.vespa.clustercontroller.core.NodeMergeStats;
import com.yahoo.vespa.clustercontroller.core.StorageMergeStats;
import com.yahoo.vespa.clustercontroller.core.StorageNodeStats;
import com.yahoo.vespa.clustercontroller.core.StorageNodeStatsContainer;
import org.junit.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author hakonhall
*/
public class StorageNodeStatsBridgeTest {
private static String getJsonString() throws IOException {
Path path = Paths.get("../protocols/getnodestate/host_info.json");
byte[] encoded;
encoded = Files.readAllBytes(path);
return new String(encoded, StandardCharsets.UTF_8);
}
@Test
public void testStorageNodeStatsContainer() throws IOException {
String data = getJsonString();
HostInfo hostInfo = HostInfo.createHostInfo(data);
StorageNodeStatsContainer container = StorageNodeStatsBridge.traverseHostInfo(hostInfo);
assertEquals(2, container.size());
StorageNodeStats node0 = container.get(0);
assertNotNull(node0);
assertEquals(15, node0.getDistributorPutLatency().getLatencyMsSum());
assertEquals(16, node0.getDistributorPutLatency().getCount());
StorageNodeStats node1 = container.get(1);
assertNotNull(node1);
assertEquals(17, node1.getDistributorPutLatency().getLatencyMsSum());
assertEquals(18, node1.getDistributorPutLatency().getCount());
}
@Test
public void testStorageMergeStats() throws IOException {
String data = getJsonString();
HostInfo hostInfo = HostInfo.createHostInfo(data);
StorageMergeStats storageMergeStats = StorageNodeStatsBridge.generate(hostInfo.getDistributor());
int size = 0;
for (NodeMergeStats mergeStats : storageMergeStats) {
assertThat(mergeStats.getCopyingIn().getBuckets(), is(2L));
assertThat(mergeStats.getCopyingOut().getBuckets(), is(4L));
assertThat(mergeStats.getSyncing().getBuckets(), is(1L));
assertThat(mergeStats.getMovingOut().getBuckets(), is(3L));
size++;
}
assertThat(size, is(2));
}
}
|