2 * Copyright 2017-2022 Open Networking Foundation and others. All rights reserved.
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;
18 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
19 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import org.junit.jupiter.api.Test;
24 * Segment descriptor test.
26 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
28 class JournalSegmentDescriptorTest {
30 * Tests the segment descriptor builder.
33 void testDescriptorBuilder() {
34 final var descriptor = JournalSegmentDescriptor.builder()
37 .withMaxSegmentSize(1024 * 1024)
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());
51 * Tests copying the segment descriptor.
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()
61 .withMaxSegmentSize(1024 * 1024)
63 .withUpdated(0x0807060504030201L)