/** * Appends the given number of entries in the given term on the server. Must be run on server's * ThreadContext. */ protected void append(int entries, long term) throws Throwable { for (int i = 0; i < entries; i++) { try (TestEntry entry = serverState.getLog().create(TestEntry.class)) { entry.setTerm(term).setTombstone(false); serverState.getLog().append(entry); } } }
protected int entrySize() { Serializer serializer = new Serializer(); serializer.register(TestEntry.class); Buffer buffer = DirectBuffer.allocate(1000); TestEntry entry = new TestEntry(); entry.setPadding(entryPadding); serializer.writeObject(entry, buffer); return (int) buffer.position() + Short.BYTES + Long.BYTES; }
/** Creates and returns the given number of entries in the given term. */ protected List<TestEntry> entries(int entries, long term) { List<TestEntry> result = new ArrayList<>(); for (int i = 0; i < entries; i++) { try (TestEntry entry = serverState.getLog().create(TestEntry.class)) { result.add(entry.setTerm(term).setTombstone(false)); } } return result; }
/** * Appends {@code numEntries} increasingly numbered ByteBuffer wrapped entries to the log, * starting at the {@code startingId}. */ protected List<Long> appendEntries(int numEntries, int startingId, Compaction.Mode mode) { List<Integer> entryIds = IntStream.range(startingId, startingId + numEntries).boxed().collect(Collectors.toList()); return entryIds .stream() .map( entryId -> { try (TestEntry entry = log.create(TestEntry.class)) { entry.setTerm(1).setCompactionMode(mode).setPadding(entryPadding); return log.append(entry); } }) .collect(Collectors.toList()); }