| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | * Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.replication.server.changelog.file; |
| | | |
| | |
| | | Record<K, V> getNewestRecord() throws ChangelogException |
| | | { |
| | | try { |
| | | final long lastBlockStart = getClosestBlockStartBeforeOrAtPosition(getFileLength()); |
| | | final long fileLength = getFileLength(); |
| | | long lastBlockStart = getClosestBlockStartBeforeOrAtPosition(fileLength); |
| | | if (lastBlockStart == fileLength) |
| | | { |
| | | // this is not a valid block start, find the previous block start |
| | | lastBlockStart = getClosestBlockStartBeforeOrAtPosition(fileLength-1); |
| | | } |
| | | positionToRecordFromBlockStart(lastBlockStart); |
| | | ByteString candidate = readNextRecord(); |
| | | ByteString record = candidate; |
| | |
| | | assertThat(reader.getClosestBlockStartBeforeOrAtPosition(20)).isEqualTo(20); |
| | | } |
| | | |
| | | @DataProvider |
| | | Object[][] recordsForNewest() |
| | | { |
| | | return new Object[][] |
| | | { |
| | | // raw size taken by each record is: 4 (record size) + 4 (key) + 4 (value) = 12 bytes |
| | | |
| | | // size of block, records to write |
| | | { 12, records(1) }, // zero block marker |
| | | { 10, records(1) }, // one block marker |
| | | { 8, records(1) }, // one block marker |
| | | { 7, records(1) }, // two block markers |
| | | { 6, records(1) }, // three block markers |
| | | { 5, records(1) }, // seven block markers |
| | | { 16, records(1,2) }, // one block marker |
| | | { 12, records(1,2) }, // two block markers |
| | | { 10, records(1,2) }, // three block markers |
| | | }; |
| | | } |
| | | |
| | | @Test(dataProvider="recordsForNewest") |
| | | public void testGetNewestRecord(int blockSize, List<Record<Integer, Integer>> records) throws Exception |
| | | { |
| | | writeRecords(blockSize, records); |
| | | |
| | | try(BlockLogReader<Integer, Integer> reader = newReader(blockSize)) |
| | | { |
| | | assertThat(reader.getNewestRecord()).isEqualTo(records.get(records.size()-1)); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void testGetClosestMarkerStrictlyAfterPosition() throws Exception |
| | | { |