2 * Copyright 2018-present Open Networking Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package io.atomix.storage.journal.index;
18 import org.junit.Test;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNull;
24 * Sparse journal index test.
26 public class SparseJournalIndexTest {
28 public void testSparseJournalIndex() throws Exception {
29 JournalIndex index = new SparseJournalIndex(.2);
30 assertNull(index.lookup(1));
32 assertNull(index.lookup(1));
37 assertEquals(5, index.lookup(5).index());
38 assertEquals(10, index.lookup(5).position());
42 assertEquals(5, index.lookup(8).index());
43 assertEquals(10, index.lookup(8).position());
46 assertEquals(10, index.lookup(10).index());
47 assertEquals(20, index.lookup(10).position());
49 assertEquals(5, index.lookup(8).index());
50 assertEquals(10, index.lookup(8).position());
51 assertEquals(5, index.lookup(10).index());
52 assertEquals(10, index.lookup(10).position());
54 assertNull(index.lookup(4));
55 assertNull(index.lookup(8));
57 index = new SparseJournalIndex(.2);
58 assertNull(index.lookup(100));
60 assertNull(index.lookup(1));
65 assertEquals(105, index.lookup(105).index());
66 assertEquals(10, index.lookup(105).position());
70 assertEquals(105, index.lookup(108).index());
71 assertEquals(10, index.lookup(108).position());
74 assertEquals(110, index.lookup(110).index());
75 assertEquals(20, index.lookup(110).position());
77 assertEquals(105, index.lookup(108).index());
78 assertEquals(10, index.lookup(108).position());
79 assertEquals(105, index.lookup(110).index());
80 assertEquals(10, index.lookup(110).position());
82 assertNull(index.lookup(104));
83 assertNull(index.lookup(108));