aboutsummaryrefslogtreecommitdiffstats
path: root/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java
blob: 066955ee36947a6b14663624945022597a16b4c9 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.flags.custom;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;

public class ClusterCapacityTest {
    @Test
    public void serialization() throws IOException {
        ClusterCapacity clusterCapacity = new ClusterCapacity(7, 1.2, 3.4, 5.6, null);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(clusterCapacity);
        assertEquals("{\"count\":7,\"vcpu\":1.2,\"memoryGb\":3.4,\"diskGb\":5.6}", json);

        ClusterCapacity deserialized = mapper.readValue(json, ClusterCapacity.class);
        assertEquals(1.2, deserialized.vcpu(), 0.0001);
        assertEquals(3.4, deserialized.memoryGb(), 0.0001);
        assertEquals(5.6, deserialized.diskGb(), 0.0001);
        assertEquals(1.0, deserialized.bandwidthGbps(), 0.0001);
        assertEquals(7, deserialized.count());
    }

    @Test
    public void serialization2() throws IOException {
        ClusterCapacity clusterCapacity = new ClusterCapacity(7, 1.2, 3.4, 5.6, 2.3);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(clusterCapacity);
        assertEquals("{\"count\":7,\"vcpu\":1.2,\"memoryGb\":3.4,\"diskGb\":5.6,\"bandwidthGbps\":2.3}", json);

        ClusterCapacity deserialized = mapper.readValue(json, ClusterCapacity.class);
        assertEquals(1.2, deserialized.vcpu(), 0.0001);
        assertEquals(3.4, deserialized.memoryGb(), 0.0001);
        assertEquals(5.6, deserialized.diskGb(), 0.0001);
        assertEquals(2.3, deserialized.bandwidthGbps(), 0.0001);
        assertEquals(7, deserialized.count());
    }
}