summaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/RoutingPolicySerializerTest.java
blob: e99cc302ffe1d9a4a5b1333747b9d3e15f91bd97 (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
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.persistence;

import com.google.common.collect.ImmutableSet;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.zone.ZoneId;
import com.yahoo.vespa.hosted.controller.application.EndpointId;
import com.yahoo.vespa.hosted.controller.application.RoutingPolicy;
import org.junit.Test;

import java.util.Iterator;
import java.util.Optional;
import java.util.Set;

import static org.junit.Assert.assertEquals;

/**
 * @author mortent
 */
public class RoutingPolicySerializerTest {

    private final RoutingPolicySerializer serializer = new RoutingPolicySerializer();

    @Test
    public void test_serialization() {
        var owner = ApplicationId.defaultId();
        var endpoints = Set.of(EndpointId.of("r1"), EndpointId.of("r2"));
        var policies = ImmutableSet.of(new RoutingPolicy(owner,
                                                         ClusterSpec.Id.from("my-cluster1"),
                                                         ZoneId.from("prod", "us-north-1"),
                                                         HostName.from("long-and-ugly-name"),
                                                         Optional.of("zone1"),
                                                         endpoints),
                                       new RoutingPolicy(owner,
                                                         ClusterSpec.Id.from("my-cluster2"),
                                                         ZoneId.from("prod", "us-north-2"),
                                                         HostName.from("long-and-ugly-name-2"),
                                                         Optional.empty(),
                                                         endpoints));
        var serialized = serializer.fromSlime(owner, serializer.toSlime(policies));
        assertEquals(policies.size(), serialized.size());
        for (Iterator<RoutingPolicy> it1 = policies.iterator(), it2 = serialized.iterator(); it1.hasNext();) {
            var expected = it1.next();
            var actual = it2.next();
            assertEquals(expected.owner(), actual.owner());
            assertEquals(expected.cluster(), actual.cluster());
            assertEquals(expected.zone(), actual.zone());
            assertEquals(expected.canonicalName(), actual.canonicalName());
            assertEquals(expected.dnsZone(), actual.dnsZone());
            assertEquals(expected.endpoints(), actual.endpoints());
        }
    }

}