Skip to content

Commit

Permalink
[Java] Formatting and warnings tidy up plus increase minor version to…
Browse files Browse the repository at this point in the history
… reflect PR #199.
  • Loading branch information
mjpt777 committed Jan 20, 2020
1 parent 8944ed3 commit 2f52118
Show file tree
Hide file tree
Showing 48 changed files with 113 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public boolean write(final int msgTypeId, final DirectBuffer srcBuffer, final in
buffer.putInt(typeOffset(recordIndex), msgTypeId);
buffer.putBytes(encodedMsgOffset(recordIndex), srcBuffer, offset, length);
buffer.putIntOrdered(lengthOffset(recordIndex), recordLength);

return true;
}

Expand Down Expand Up @@ -447,6 +448,7 @@ private int computeRecordIndex(final int index)
{
throw new IllegalArgumentException("invalid message index " + index);
}

return recordIndex;
}

Expand All @@ -457,7 +459,8 @@ private int verifyClaimedSpaceNotReleased(final AtomicBuffer buffer, final int r
{
return recordLength;
}
throw new IllegalStateException("claimed space was already " +

throw new IllegalStateException("claimed space previously " +
(PADDING_MSG_TYPE_ID == buffer.getInt(typeOffset(recordIndex)) ? "aborted" : "committed"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public boolean write(final int msgTypeId, final DirectBuffer srcBuffer, final in
buffer.putBytes(encodedMsgOffset(recordIndex), srcBuffer, offset, length);
buffer.putInt(typeOffset(recordIndex), msgTypeId);
buffer.putIntOrdered(lengthOffset(recordIndex), recordLength);

return true;
}

Expand Down Expand Up @@ -265,6 +266,7 @@ public int tryClaim(final int msgTypeId, final int length)
// hence the order of writes of type field and negative length does not matter.
// It is safe to do so, because the header was pre-zeroed during the capacity claim.
buffer.putInt(lengthOffset(recordIndex), -recordLength);

return encodedMsgOffset(recordIndex);
}

Expand Down Expand Up @@ -363,7 +365,6 @@ private int claimCapacity(final AtomicBuffer buffer, final int recordLength)
}

buffer.putLong(recordIndex + alignedRecordLength, 0L); // pre-zero next message header

buffer.putLongOrdered(tailPositionIndex, tail + alignedRecordLength + padding);

return recordIndex;
Expand All @@ -376,6 +377,7 @@ private int computeRecordIndex(final int index)
{
throw new IllegalArgumentException("invalid message index " + index);
}

return recordIndex;
}

Expand All @@ -386,7 +388,8 @@ private int verifyClaimedSpaceNotReleased(final AtomicBuffer buffer, final int r
{
return recordLength;
}
throw new IllegalStateException("claimed space was already " +

throw new IllegalStateException("claimed space previously " +
(PADDING_MSG_TYPE_ID == buffer.getInt(typeOffset(recordIndex)) ? "aborted" : "committed"));
}
}
2 changes: 1 addition & 1 deletion agrona/src/test/java/org/agrona/AsciiEncodingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ public void shouldThrowExceptionWhenParsingEmptyInteger()
{
assertThrows(IndexOutOfBoundsException.class, () -> AsciiEncoding.parseIntAscii("", 0, 0));
}
}
}
2 changes: 1 addition & 1 deletion agrona/src/test/java/org/agrona/AsciiSequenceViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ public void shouldThrowExceptionWhenCharAtCalledWithNegativeIndex()

assertThrows(StringIndexOutOfBoundsException.class, () -> asciiSequenceView.charAt(-1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ private static Stream<MutableDirectBuffer> buffers()
new UnsafeBuffer(new byte[BUFFER_CAPACITY]),
new UnsafeBuffer(ByteBuffer.allocateDirect(BUFFER_CAPACITY)),
new ExpandableArrayBuffer(BUFFER_CAPACITY),
new ExpandableDirectByteBuffer(BUFFER_CAPACITY)
);
new ExpandableDirectByteBuffer(BUFFER_CAPACITY));
}

@ParameterizedTest
Expand Down
2 changes: 1 addition & 1 deletion agrona/src/test/java/org/agrona/BufferUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ public void shouldAlignToCacheLineBoundary()
assertTrue(isAligned(address, CACHE_LINE_LENGTH));
assertThat(byteBuffer.capacity(), is(capacity));
}
}
}
2 changes: 1 addition & 1 deletion agrona/src/test/java/org/agrona/LangUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ private static void throwHiddenCheckedException()
LangUtil.rethrowUnchecked(t);
}
}
}
}
23 changes: 19 additions & 4 deletions agrona/src/test/java/org/agrona/MarkFileTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2014-2020 Real Logic Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.agrona;

import org.agrona.concurrent.SystemEpochClock;
Expand All @@ -22,7 +37,6 @@ public class MarkFileTest
@Test
public void shouldWaitForMarkFileToContainEnoughDataForVersionCheck() throws IOException
{

final String filename = "markfile.dat";
final Path markFilePath = directory.toPath().resolve(filename);
Files.createFile(markFilePath);
Expand All @@ -31,7 +45,8 @@ public void shouldWaitForMarkFileToContainEnoughDataForVersionCheck() throws IOE
{
channel.write(ByteBuffer.allocate(1));
}
assertThrows(IllegalStateException.class, () ->
new MarkFile(directory, filename, 0, 16, 10, new SystemEpochClock(), v -> {}, msg -> {}));

assertThrows(IllegalStateException.class,
() -> new MarkFile(directory, filename, 0, 16, 10, new SystemEpochClock(), v -> {}, msg -> {}));
}
}
}
2 changes: 1 addition & 1 deletion agrona/src/test/java/org/agrona/PrintBufferUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ public void shouldPrettyPrintHex()
PrintBufferUtil.appendPrettyHexDump(builder, buffer);
assertThat(builder.toString(), containsString("0...Hello World!"));
}
}
}
1 change: 0 additions & 1 deletion agrona/src/test/java/org/agrona/ReferencesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ public void validateIsReferringTo()
assertFalse(References.isReferringTo(ref, objTwo));
}
}

2 changes: 1 addition & 1 deletion agrona/src/test/java/org/agrona/SemanticVersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ public void shouldConvertToString()

assertEquals("17.9.127", SemanticVersion.toString(version));
}
}
}
2 changes: 1 addition & 1 deletion agrona/src/test/java/org/agrona/SystemUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ public void shouldOverrideSystemPropertiesWithConfigFromPropFile()

System.clearProperty("TestFileA.foo");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

import org.junit.jupiter.api.Test;

import static java.lang.Integer.valueOf;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

public class ArrayUtilTest
{
// Reference Equality
private static final Integer ONE = valueOf(1);
private static final Integer TWO = valueOf(2);
private static final Integer THREE = valueOf(3);
private static final Integer ONE = 1;
private static final Integer TWO = 2;
private static final Integer THREE = 3;

private final Integer[] values = { ONE, TWO };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,4 @@ public int hashCode()
return result;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@

@RunWith(Suite.class)
@SuiteClasses({
Int2ObjectHashMapConformanceTest.class, Int2IntHashMapConformanceTest.class,
Int2ObjectHashMapConformanceTest.class,
Int2IntHashMapConformanceTest.class,
Int2NullableObjectHashMapConformanceTest.class,
Long2ObjectHashMapConformanceTest.class, Long2LongHashMapConformanceTest.class,
Long2ObjectHashMapConformanceTest.class,
Long2LongHashMapConformanceTest.class,
Long2NullableObjectHashMapConformanceTest.class,
Object2IntHashMapConformanceTest.class, Object2LongHashMapConformanceTest.class,
Object2ObjectHashMapConformanceTest.class, Object2NullableObjectHashMapConformanceTest.class})
Object2IntHashMapConformanceTest.class,
Object2LongHashMapConformanceTest.class,
Object2ObjectHashMapConformanceTest.class,
Object2NullableObjectHashMapConformanceTest.class})
public class ConformanceTestsSuite
{
// This is required so that the suites are picked up by gradle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGe
.named(name)
.createTestSuite();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

public class Int2IntHashMapNotAvoidingAllocationTest extends Int2IntHashMapTest
{

@BeforeEach
void before()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void shouldExceptionWhenRunningOutOfElements()
iterator.next();
iterator.next();

assertThrows(NoSuchElementException.class, () -> iterator.next());
assertThrows(NoSuchElementException.class, iterator::next);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGe
.named(name)
.createTestSuite();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,3 @@ public void shouldTestStats()
assertThat(cache.cacheHits(), is(0L));
}
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2014-2020 Real Logic Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.agrona.collections;

import com.google.common.collect.testing.Helpers;
Expand All @@ -12,7 +27,6 @@
import java.util.List;
import java.util.Map;


public class Int2ObjectHashMapConformanceTest
{
// Generated suite to test conformity to the java.util.Set interface
Expand Down Expand Up @@ -82,4 +96,4 @@ private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGe
.named(name)
.createTestSuite();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void shouldIterateKeysGettingIntAsPrimitive()

final Collection<Integer> copyToSet = new HashSet<>();

for (final Int2ObjectHashMap.KeyIterator iter = intToObjectMap.keySet().iterator(); iter.hasNext(); )
for (final Int2ObjectHashMap<String>.KeyIterator iter = intToObjectMap.keySet().iterator(); iter.hasNext(); )
{
copyToSet.add(iter.nextInt());
}
Expand Down Expand Up @@ -425,4 +425,3 @@ protected String unmapNullValue(final Object value)
assertThat(map.size(), is(1));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,4 @@ public void shouldWrapLessZeroLengthArrayThenGrow()
list.addInt(7);
assertThat(list.capacity(), is(IntArrayList.INITIAL_CAPACITY));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void shouldIterateEmptyQueue()
{
final IntArrayQueue queue = new IntArrayQueue();

for (final int i : queue)
for (final int ignore : queue)
{
fail("Should be empty");
}
Expand All @@ -184,7 +184,7 @@ public void shouldIterateEmptyQueue()
queue.removeInt();
}

for (final int i : queue)
for (final int ignore : queue)
{
fail("Should be empty");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,15 +818,15 @@ public void shouldHaveCompatibleEqualsAndHashcode()
{
final HashSet<Integer> compatibleSet = new HashSet<>();
final long seed = System.nanoTime();
final Random r = new Random(seed);
final Random random = new Random(seed);
for (int i = 0; i < 1024; i++)
{
final int value = r.nextInt();
final int value = random.nextInt();
compatibleSet.add(value);
testSet.add(value);
}

if (r.nextBoolean())
if (random.nextBoolean())
{
compatibleSet.add(MISSING_VALUE);
testSet.add(MISSING_VALUE);
Expand Down Expand Up @@ -888,7 +888,7 @@ private static void assertContainsElements(final Set<Integer> other)

private void exhaustIterator()
{
final Iterator iterator = testSet.iterator();
final Iterator<Integer> iterator = testSet.iterator();
iterator.next();
iterator.next();
iterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.Map;


public class Long2LongHashMapConformanceTest
{
// Generated suite to test conformity to the java.util.Set interface
Expand Down Expand Up @@ -97,4 +96,4 @@ private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGe
.named(name)
.createTestSuite();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGe
.named(name)
.createTestSuite();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGe
.named(name)
.createTestSuite();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGe
.named(name)
.createTestSuite();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGe
.named(name)
.createTestSuite();
}
}
}
Loading

0 comments on commit 2f52118

Please sign in to comment.