Bump versions 9.0.4-SNAPSHOT
[controller.git] / atomix-storage / src / test / java / io / atomix / storage / journal / JournalSegmentDescriptorTest.java
1 /*
2  * Copyright 2017-2022 Open Networking Foundation and others.  All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package io.atomix.storage.journal;
17
18 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20
21 import org.junit.jupiter.api.Test;
22
23 /**
24  * Segment descriptor test.
25  *
26  * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
27  */
28 class JournalSegmentDescriptorTest {
29     /**
30      * Tests the segment descriptor builder.
31      */
32     @Test
33     void testDescriptorBuilder() {
34         final var descriptor = JournalSegmentDescriptor.builder()
35             .withId(2)
36             .withIndex(1025)
37             .withMaxSegmentSize(1024 * 1024)
38             .withMaxEntries(2048)
39             .withUpdated(0)
40             .build();
41
42         assertEquals(2, descriptor.id());
43         assertEquals(JournalSegmentDescriptor.VERSION, descriptor.version());
44         assertEquals(1025, descriptor.index());
45         assertEquals(1024 * 1024, descriptor.maxSegmentSize());
46         assertEquals(2048, descriptor.maxEntries());
47         assertEquals(0, descriptor.updated());
48     }
49
50     /**
51      * Tests copying the segment descriptor.
52      */
53     @Test
54     void testToArray() {
55         assertArrayEquals(new byte[] {
56             0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 4, 1, 0, 16, 0, 0, 0, 0, 8, 0, 8, 7, 6, 5,
57             4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58         }, JournalSegmentDescriptor.builder()
59             .withId(2)
60             .withIndex(1025)
61             .withMaxSegmentSize(1024 * 1024)
62             .withMaxEntries(2048)
63             .withUpdated(0x0807060504030201L)
64             .build()
65             .toArray());
66     }
67 }