blob: 435b6e3a28a09282a7c024a362ae6afe2a8707a3 (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;
import org.junit.Test;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Ulf Lilleengen
*/
public class ProvisionInfoTest {
private final HostSpec h1 = new HostSpec("host1", Optional.empty());
private final HostSpec h2 = new HostSpec("host2", Optional.empty());
private final HostSpec h3 = new HostSpec("host3", Optional.of(ClusterMembership.from("container/test/0", com.yahoo.component.Version.fromString("6.73.1"))));
@Test
public void testProvisionInfoSerialization() throws IOException {
Set<HostSpec> hosts = new LinkedHashSet<>();
hosts.add(h1);
hosts.add(h2);
hosts.add(h3);
ProvisionInfo info = ProvisionInfo.withHosts(hosts);
assertProvisionInfo(info);
}
private void assertProvisionInfo(ProvisionInfo info) throws IOException {
ProvisionInfo serializedInfo = ProvisionInfo.fromJson(info.toJson(), Optional.empty());
assertEquals(info.getHosts().size(), serializedInfo.getHosts().size());
assertTrue(serializedInfo.getHosts().contains(h1));
assertTrue(serializedInfo.getHosts().contains(h2));
assertTrue(serializedInfo.getHosts().contains(h3));
assertTrue(!getHost(h1.hostname(), serializedInfo.getHosts()).membership().isPresent());
assertEquals("container/test/0", getHost(h3.hostname(), serializedInfo.getHosts()).membership().get().stringValue());
assertEquals(h3.membership().get().cluster().vespaVersion(), getHost(h3.hostname(), serializedInfo.getHosts()).membership().get().cluster().vespaVersion());
}
private HostSpec getHost(String hostname, Set<HostSpec> hosts) {
for (HostSpec host : hosts)
if (host.hostname().equals(hostname))
return host;
throw new IllegalArgumentException("No host " + hostname + " is present");
}
}
|