aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/ReindexingMaintainerTest.java
blob: f3c86388fae43d905f3b1971240e4dfa052d2354 (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
78
79
80
81
82
83
// 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.maintenance;

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

import java.time.Instant;
import java.util.List;
import java.util.Map;

import static com.yahoo.vespa.config.server.maintenance.ReindexingMaintainer.CAUSE;
import static com.yahoo.vespa.config.server.maintenance.ReindexingMaintainer.SPEED;
import static com.yahoo.vespa.config.server.maintenance.ReindexingMaintainer.withNewReady;
import static com.yahoo.vespa.config.server.maintenance.ReindexingMaintainer.withOnlyCurrentData;
import static org.junit.Assert.assertEquals;

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

    @Test
    public void testReadyComputation() {
        ApplicationReindexing reindexing = ApplicationReindexing.empty()
                                                                .withPending("one", "a", 10)
                                                                .withPending("two", "b", 20)
                                                                .withReady("one", "a", Instant.ofEpochMilli(3), SPEED, CAUSE)
                                                                .withReady("two", "b", Instant.ofEpochMilli(2), SPEED, CAUSE)
                                                                .withReady("two", "c", Instant.ofEpochMilli(3), SPEED, CAUSE);

        // Nothing happens without convergence.
        assertEquals(reindexing,
                     withNewReady(reindexing, () -> -1L, Instant.EPOCH));

        // Status for (one, a) changes, but not (two, b).
        Instant later = Instant.ofEpochMilli(3 << 10);
        // Converged, no longer pending.
        assertEquals(reindexing.withoutPending("one", "a").withReady("one", "a", later, SPEED, CAUSE),   // Converged, now ready.
                     withNewReady(reindexing, () -> 19L, later));

        // Converged, no longer pending.
        // Converged, no Longer pending.
        assertEquals(reindexing.withoutPending("one", "a").withReady("one", "a", later, SPEED, CAUSE)
                               .withoutPending("two", "b").withReady("two", "b", later, SPEED, CAUSE),
                     withNewReady(reindexing, () -> 20L, later));

        // Verify generation supplier isn't called when no pending document types.
        withNewReady(reindexing.withoutPending("one", "a").withoutPending("two", "b"),
                     () -> { throw new AssertionError("not supposed to run"); },
                     later);
    }

    @Test
    public void testGarbageRemoval() {
        ApplicationReindexing reindexing = ApplicationReindexing.empty()
                                                                .withPending("one", "a", 10)
                                                                .withPending("two", "b", 20)
                                                                .withReady("one", "a", Instant.ofEpochMilli(3), SPEED, CAUSE)
                                                                .withReady("two", "b", Instant.ofEpochMilli(2), SPEED, CAUSE)
                                                                .withReady("two", "c", Instant.ofEpochMilli(3), SPEED, CAUSE);

        assertEquals(reindexing,
                     withOnlyCurrentData(reindexing, Map.of("one", List.of("a", "b", "c", "d"),
                                                            "two", List.of("b", "c"),
                                                            "three", List.of("a", "b"))));

        assertEquals(reindexing,
                     withOnlyCurrentData(reindexing, Map.of("one", List.of("a"),
                                                            "two", List.of("b", "c"))));

        assertEquals(ApplicationReindexing.empty()
                                          .withPending("two", "b", 20).withReady("two", "b", Instant.ofEpochMilli(2), SPEED, CAUSE),
                     withOnlyCurrentData(reindexing, Map.of("two", List.of("a", "b"))));

        assertEquals(ApplicationReindexing.empty()
                                          .withReady("one", "a", Instant.EPOCH, SPEED, CAUSE)
                                          .without("one", "a")
                                          .withReady("two", "c", Instant.ofEpochMilli(3), SPEED, CAUSE),
                     withOnlyCurrentData(reindexing, Map.of("one", List.of("c"),
                                                            "two", List.of("c"))));
    }

}