Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,5 +360,4 @@ static int cardinality(byte[] bits) {
}
return cnt;
}

}
28 changes: 18 additions & 10 deletions src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.HashMap;
Expand Down Expand Up @@ -356,7 +357,10 @@
final int headerSize) throws IOException {
//noinspection PointlessBitwiseExpression
headerBuffer.putInt(SIZE_WORD_OFFSET, NOT_COMPLETE | DATA | headerSize);
headerBuffer.clear().position(SIZE_WORD_OFFSET).limit(SIZE_WORD_OFFSET + 4);
final Buffer headerView = headerBuffer;
headerView.clear();
headerView.position(SIZE_WORD_OFFSET);
headerView.limit(SIZE_WORD_OFFSET + 4);
writeFully(fileChannel, SIZE_WORD_OFFSET, headerBuffer);
}

Expand Down Expand Up @@ -388,11 +392,12 @@
headerBuffer.putInt(SIZE_WORD_OFFSET, NOT_COMPLETE | DATA | headerSize);

// Write the size-prefixed blob to the file
headerBuffer.position(0);
headerBuffer.limit(headerLimit);
final Buffer headerView = headerBuffer;
headerView.position(0);
headerView.limit(headerLimit);
writeFully(fileChannel, 0, headerBuffer);

headerBuffer.position(SELF_BOOTSTRAPPING_HEADER_OFFSET);
headerView.position(SELF_BOOTSTRAPPING_HEADER_OFFSET);
return headerBuffer;
}

Expand All @@ -406,7 +411,10 @@

//noinspection PointlessBitwiseExpression
headerBuffer.putInt(SIZE_WORD_OFFSET, READY | DATA | headerSize);
headerBuffer.clear().position(SIZE_WORD_OFFSET).limit(SIZE_WORD_OFFSET + 4);
final Buffer headerView = headerBuffer;
headerView.clear();
headerView.position(SIZE_WORD_OFFSET);
headerView.limit(SIZE_WORD_OFFSET + 4);
writeFully(fileChannel, SIZE_WORD_OFFSET, headerBuffer);
}

Expand Down Expand Up @@ -446,7 +454,7 @@
throw new IOException("file=" + file + ": sizeWord is not ready: " + sizeWord);
}
}
headerBuffer.position(SELF_BOOTSTRAPPING_HEADER_OFFSET);
((Buffer) headerBuffer).position(SELF_BOOTSTRAPPING_HEADER_OFFSET);

Check warning on line 457 in src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary cast to "Buffer".

See more on https://sonarcloud.io/project/issues?id=OpenHFT_Chronicle-Map&issues=AZ6D2jLrNrsyk6IOrZq0&open=AZ6D2jLrNrsyk6IOrZq0&pullRequest=588
return headerBuffer;
}

Expand Down Expand Up @@ -1267,8 +1275,8 @@
* previous mapped value on {@code putIfAbsent()} calls and does not change the supplied value.
*
* @param putIfAbsentUsingValue {@code true} if you want {@link ChronicleMap#putIfAbsent(Object, Object)
* ChronicleMap.putIfAbsent()} to not return the value that was replaced but
* instead return {@code null}
* ChronicleMap.putIfAbsent()} to not return the value that was replaced but
* instead return {@code null}
* @return this builder back
* @see #putReturnsNull(boolean)
*/
Expand Down Expand Up @@ -1789,7 +1797,7 @@
for (int attempt = 0; attempt < attempts; attempt++) {
if (raf.length() >= SELF_BOOTSTRAPPING_HEADER_OFFSET) {

sizeWordBuffer.clear();
((Buffer) sizeWordBuffer).clear();
readFully(fileChannel, SIZE_WORD_OFFSET, sizeWordBuffer);
if (sizeWordBuffer.remaining() == 0) {
int sizeWord = sizeWordBuffer.getInt(0);
Expand Down Expand Up @@ -1976,7 +1984,7 @@
return (VanillaChronicleMap<K, V, ?>) Class.forName(replicatedMapClassName).
getDeclaredConstructor(getClass()).newInstance(this);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException | ClassNotFoundException e) {
InvocationTargetException | ClassNotFoundException e) {
throw new IllegalStateException("Cannot load specified implementation class: " + replicatedMapClassName,
e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ public final class MapFileAnalyzer {
public static void main(String[] args) throws IOException {
InternalMapFileAnalyzer.main(args);
}

}
6 changes: 3 additions & 3 deletions src/test/java/eg/AverageValueSizeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.MapSegmentContext;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.LongSummaryStatistics;

public class AverageValueSizeTest {
class AverageValueSizeTest {

public static <V> double averageValueSize(Class<V> valueClass, Iterable<V> values) {
try (ChronicleMap<Integer, V> testMap = ChronicleMap.of(Integer.class, valueClass)
Expand All @@ -29,7 +29,7 @@ public static <V> double averageValueSize(Class<V> valueClass, Iterable<V> value
}

@Test
public void averageValueSizeTest() {
void averageValueSizeTest() {
System.out.println(averageValueSize(String.class,
Arrays.asList("banana", "apple", "watermelon")));
}
Expand Down
27 changes: 14 additions & 13 deletions src/test/java/eg/OffHeapByteArrayExampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@
import net.openhft.chronicle.map.ChronicleMapBuilder;
import net.openhft.chronicle.values.Array;
import net.openhft.chronicle.values.Values;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class OffHeapByteArrayExampleTest {
import static org.junit.jupiter.api.Assertions.*;

class OffHeapByteArrayExampleTest {

public static final char EXPECTED = 'b';
private static ChronicleMap<LongValue, ByteArray> chm;

@BeforeClass
public static void beforeClass() {
@BeforeAll
static void beforeClass() {
chm = ChronicleMapBuilder
.of(LongValue.class, ByteArray.class)
.entries(1000)
.create();
}

@AfterClass
public static void afterClass() {
@AfterAll
static void afterClass() {
if (chm != null)
chm.close();
}

@Test
public void test() {
void test() {

// this objects will be reused
ByteValue byteValue = Values.newHeapInstance(ByteValue.class);
Expand All @@ -55,11 +56,11 @@ public void test() {

chm.getUsing(key, value);

Assert.assertEquals(0, value.getByteValueAt(2).getValue());
Assert.assertEquals(0, value.getByteValueAt(3).getValue());
assertEquals(0, value.getByteValueAt(2).getValue());
assertEquals(0, value.getByteValueAt(3).getValue());

byte actual = value.getByteValueAt(1).getValue();
Assert.assertEquals(EXPECTED, actual);
assertEquals(EXPECTED, actual);

}

Expand Down
10 changes: 4 additions & 6 deletions src/test/java/eg/WordCountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.openhft.chronicle.core.values.IntValue;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.values.Values;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -21,10 +21,9 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.reducing;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;

public class WordCountTest {
class WordCountTest {

static final String[] words;
static final Map<CharSequence, Integer> expectedMap;
Expand All @@ -48,9 +47,8 @@ public class WordCountTest {
}
}

///@Ignore("https://github.com/OpenHFT/Chronicle-Map/issues/376")
@Test
public void wordCountTest() {
void wordCountTest() {
try (ChronicleMap<CharSequence, IntValue> map = ChronicleMap
.of(CharSequence.class, IntValue.class)
.averageKeySize(7) // average word is 7 ascii bytes long (text in english)
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/examples/portfolio/PortfolioValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
import net.openhft.chronicle.threads.NamedThreadFactory;
import net.openhft.chronicle.values.Values;
import org.apache.commons.lang3.mutable.MutableDouble;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@SuppressWarnings({"rawtypes", "unchecked"})
public class PortfolioValueTest {
class PortfolioValueTest {
private static final boolean useIterator = true;
private static final long nAssets = 10_000_000;
private static final int nThreads = Runtime.getRuntime().availableProcessors();
Expand Down Expand Up @@ -92,7 +92,7 @@ protected static double computeTotalUsingKeys(final ChronicleMap<LongValue, Port
}

@Test
public void test() throws ExecutionException, InterruptedException {
void test() throws ExecutionException, InterruptedException {
ChronicleMapBuilder<LongValue, PortfolioAssetInterface> mapBuilder = ChronicleMapBuilder.of(LongValue.class, PortfolioAssetInterface.class).entries(nAssets);

try (ChronicleMap<LongValue, PortfolioAssetInterface> cache = mapBuilder.create()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
*/
package net.openhft.chronicle.hash.impl.util;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

public class CleanerUtilsTest {
class CleanerUtilsTest {

@Test
public void testClean() throws InterruptedException {
void testClean() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
Object ob = new Object();
Cleaner cleaner = CleanerUtils.createCleaner(ob, latch::countDown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,82 @@
*/
package net.openhft.chronicle.hash.impl.util;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public class ThrowablesTest {
class ThrowablesTest {

@Test(expected = NullPointerException.class)
public void testPropagateNull() {
Throwables.propagate(null);
@Test
void testPropagateNull() {
assertThrows(NullPointerException.class, () -> {
Throwables.propagate(null);
});
}

@Test(expected = AssertionError.class)
public void testPropagateError() {
Throwables.propagate(new AssertionError());
@Test
void testPropagateError() {
assertThrows(AssertionError.class, () -> {
Throwables.propagate(new AssertionError());
});
}

@Test(expected = IllegalStateException.class)
public void testPropagateUncheckedException() {
Throwables.propagate(new IllegalStateException());
@Test
void testPropagateUncheckedException() {
assertThrows(IllegalStateException.class, () -> {
Throwables.propagate(new IllegalStateException());
});
}

@Test(expected = RuntimeException.class)
public void testPropagateCheckedException() {
Throwables.propagate(new IOException());
@Test
void testPropagateCheckedException() {
assertThrows(RuntimeException.class, () -> {
Throwables.propagate(new IOException());
});
}

@Test(expected = NullPointerException.class)
public void testPropagateNotWrappingNull() throws IOException {
Throwables.propagateNotWrapping(null, IOException.class);
@Test
void testPropagateNotWrappingNull() throws IOException {

Check warning on line 44 in src/test/java/net/openhft/chronicle/hash/impl/util/ThrowablesTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body.

See more on https://sonarcloud.io/project/issues?id=OpenHFT_Chronicle-Map&issues=AZ6D2jKHNrsyk6IOrZqo&open=AZ6D2jKHNrsyk6IOrZqo&pullRequest=588
assertThrows(NullPointerException.class, () -> {
Throwables.propagateNotWrapping(null, IOException.class);
});
}

@Test(expected = NullPointerException.class)
public void testPropagateNotWrappingNullWrappingType() throws Throwable {
Throwables.propagateNotWrapping(new IOException(), null);
@Test
void testPropagateNotWrappingNullWrappingType() throws Throwable {
assertThrows(NullPointerException.class, () -> {
Throwables.propagateNotWrapping(new IOException(), null);
});
}

@Test(expected = AssertionError.class)
public void testPropagateNotWrappingError() throws IOException {
Throwables.propagateNotWrapping(new AssertionError(), IOException.class);
@Test
void testPropagateNotWrappingError() throws IOException {
assertThrows(AssertionError.class, () -> {
Throwables.propagateNotWrapping(new AssertionError(), IOException.class);
});
}

@Test(expected = IllegalStateException.class)
public void testPropagateNotWrappingUncheckedException() throws IOException {
Throwables.propagateNotWrapping(new IllegalStateException(), IOException.class);
@Test
void testPropagateNotWrappingUncheckedException() throws IOException {
assertThrows(IllegalStateException.class, () -> {
Throwables.propagateNotWrapping(new IllegalStateException(), IOException.class);
});
}

@Test(expected = IOException.class)
public void testPropagateNotWrappingNotWrappingEException() throws IOException {
Throwables.propagateNotWrapping(new IOException(), IOException.class);
@Test
void testPropagateNotWrappingNotWrappingEException() throws IOException {
assertThrows(IOException.class, () -> {
Throwables.propagateNotWrapping(new IOException(), IOException.class);
});
}

@Test(expected = RuntimeException.class)
public void testPropagateNotWrappingCheckedException() throws IOException {
Throwables.propagateNotWrapping(new Exception(), IOException.class);
@Test
void testPropagateNotWrappingCheckedException() throws IOException {
assertThrows(RuntimeException.class, () -> {
Throwables.propagateNotWrapping(new Exception(), IOException.class);
});
}
}
Loading