2 * Copyright 2017-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;
18 import org.junit.Test;
20 import java.nio.ByteBuffer;
22 import static org.junit.Assert.assertEquals;
25 * Segment descriptor test.
27 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
29 public class JournalSegmentDescriptorTest {
32 * Tests the segment descriptor builder.
35 public void testDescriptorBuilder() {
36 JournalSegmentDescriptor descriptor = JournalSegmentDescriptor.builder(ByteBuffer.allocate(JournalSegmentDescriptor.BYTES))
39 .withMaxSegmentSize(1024 * 1024)
43 assertEquals(2, descriptor.id());
44 assertEquals(JournalSegmentDescriptor.VERSION, descriptor.version());
45 assertEquals(1025, descriptor.index());
46 assertEquals(1024 * 1024, descriptor.maxSegmentSize());
47 assertEquals(2048, descriptor.maxEntries());
49 assertEquals(0, descriptor.updated());
50 long time = System.currentTimeMillis();
51 descriptor.update(time);
52 assertEquals(time, descriptor.updated());
56 * Tests copying the segment descriptor.
59 public void testDescriptorCopy() {
60 JournalSegmentDescriptor descriptor = JournalSegmentDescriptor.builder()
63 .withMaxSegmentSize(1024 * 1024)
67 long time = System.currentTimeMillis();
68 descriptor.update(time);
70 descriptor = descriptor.copyTo(ByteBuffer.allocate(JournalSegmentDescriptor.BYTES));
72 assertEquals(2, descriptor.id());
73 assertEquals(JournalSegmentDescriptor.VERSION, descriptor.version());
74 assertEquals(1025, descriptor.index());
75 assertEquals(1024 * 1024, descriptor.maxSegmentSize());
76 assertEquals(2048, descriptor.maxEntries());
77 assertEquals(time, descriptor.updated());