aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/application/ApplicationReindexingTest.java
blob: 14d28363aa696d392bc5b6712d04f8f3c169d2ae (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
68
69
70
71
72
73
74
75
76
77
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.application;

import com.yahoo.vespa.config.server.application.ApplicationReindexing.Status;
import org.junit.Test;

import java.time.Instant;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * @author jonmv
 */
public class ApplicationReindexingTest {

    @Test
    public void test() {
        ApplicationReindexing reindexing = ApplicationReindexing.empty()
                                                                .withPending("one", "a", 10)
                                                                .withReady("two", "b", Instant.ofEpochMilli(2), 3, "test reindexing")
                                                                .withPending("two", "b", 20)
                                                                .withReady("one", "a", Instant.ofEpochMilli(1), 1, "test reindexing")
                                                                .withReady("two", "a", Instant.ofEpochMilli(3), 2, "test reindexing")
                                                                .withoutPending("one", "a");

        assertEquals(Instant.ofEpochMilli(1),
                     reindexing.status("one", "a").orElseThrow().ready());
        assertEquals(Optional.empty(),
                     reindexing.status("one", "b"));

        assertEquals(Instant.ofEpochMilli(2),
                     reindexing.status("two", "b").orElseThrow().ready());
        assertEquals(Instant.ofEpochMilli(3),
                     reindexing.status("two", "a").orElseThrow().ready());

        assertEquals(Optional.empty(),
                     reindexing.status("three", "a"));

        assertEquals(Optional.empty(),
                     reindexing.lastReadiedAt());
        assertEquals(Optional.of(Instant.ofEpochMilli(3)),
                     reindexing.withoutPending("two", "b").lastReadiedAt());

        // Remove "a" in "one", and "one" entirely.
        assertEquals(Optional.empty(),
                     reindexing.without("one", "a").status("one", "a"));
        assertEquals(Optional.empty(),
                     reindexing.without("one").status("one", "a"));

        // Verify content of "reindexing".
        assertEquals(Set.of("one", "two"),
                     reindexing.clusters().keySet());

        assertEquals(Map.of("a", new Status(Instant.ofEpochMilli(1), 1, "test reindexing")),
                     reindexing.clusters().get("one").ready());

        assertEquals(Map.of(),
                     reindexing.clusters().get("one").pending());

        assertEquals(Map.of("a", new Status(Instant.ofEpochMilli(3), 2, "test reindexing"),
                            "b", new Status(Instant.ofEpochMilli(2), 3, "test reindexing")),
                     reindexing.clusters().get("two").ready());

        assertEquals(Map.of("b", 20L),
                     reindexing.clusters().get("two").pending());

        assertTrue(reindexing.enabled());

        assertFalse(reindexing.enabled(false).enabled());
    }

}