Skip to content

Commit

Permalink
Changes proposed by reviewers, spotless:apply.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-Draeger committed Jun 28, 2023
1 parent 0242b52 commit 78aa83b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- message encoding errors are summarized by default, but all information is available via the configuration option
SDCcc.SummarizeMessageEncodingErrors.
- checking for message encoding errors can be disabled using the configuration option SDCcc.EnableMessageEncodingCheck.
- when enabled, SDCcc also checks if message bodies can be decoded using the encoding specified.
- configuration option SDCcc.Network.MulticastTTL to configure the Time To Live of the Multicast Packets used for Discovery.
- SDCcc now checks the encodings of all messages when SDCcc.EnableMessageEncodingCheck is enabled.

### Changed
- SDCri version 4.1.0-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -171,7 +172,7 @@ public class MessageStorage implements AutoCloseable {

private final TestRunObserver testRunObserver;
private final boolean summarizeMessageEncodingErrors;
private long messageEncodingErrorCount;
private AtomicLong messageEncodingErrorCount;
private int invalidMimeTypeCount;
private final boolean enableEncodingCheck;

Expand All @@ -189,7 +190,7 @@ public class MessageStorage implements AutoCloseable {
this.blockingQueueSize = blockingQueueSize;
this.summarizeMessageEncodingErrors = summarizeMessageEncodingErrors;
this.enableEncodingCheck = enableEncodingCheck;
this.messageEncodingErrorCount = 0;
this.messageEncodingErrorCount = new AtomicLong(0);
this.invalidMimeTypeCount = 0;

this.actionExtractor = new XPathExtractor(String.format("//%s:Action", WsAddressingConstants.NAMESPACE_PREFIX));
Expand Down Expand Up @@ -284,7 +285,7 @@ protected MessageContent convertMessageToMessageContent(final Message message) {
if (this.enableEncodingCheck) {
if (this.summarizeMessageEncodingErrors) {
// TestRun will be invalidated in TestSuite if messageEncodingErrorCount > 0
this.messageEncodingErrorCount += 1;
this.messageEncodingErrorCount.incrementAndGet();
} else {
this.testRunObserver.invalidateTestRun(String.format(
"Encountered message encoding problem: charset %s was specified, but message "
Expand Down Expand Up @@ -374,7 +375,7 @@ protected Charset determineCharsetFromMessage(final Message message) {
(String originA, String valueA, String originB, String valueB) -> {
if (this.summarizeMessageEncodingErrors) {
// TestRun will be invalidated in TestSuite if messageEncodingErrorCount > 0
this.messageEncodingErrorCount += 1;
this.messageEncodingErrorCount.incrementAndGet();
} else {
this.testRunObserver.invalidateTestRun(String.format(
INCONSISTENT_CHARSET_DECLARATION_WITH_ORIGINS,
Expand All @@ -398,7 +399,7 @@ protected Charset determineCharsetFromMessage(final Message message) {
}
if (this.summarizeMessageEncodingErrors) {
// TestRun will be invalidated in TestSuite if messageEncodingErrorCount > 0
this.messageEncodingErrorCount++;
this.messageEncodingErrorCount.incrementAndGet();
} else {
this.testRunObserver.invalidateTestRun(String.format(
"Encountered a message whose encoding is declared to be %s. This violates"
Expand Down Expand Up @@ -433,7 +434,7 @@ private Charset chooseMessageCharset(
} else {
if (this.summarizeMessageEncodingErrors) {
// TestRun will be invalidated in TestSuite if messageEncodingErrorCount > 0
this.messageEncodingErrorCount += 1;
this.messageEncodingErrorCount.incrementAndGet();
} else {
this.testRunObserver.invalidateTestRun(
"Message encoding could not be determined for message with ID '" + message.getID()
Expand Down Expand Up @@ -541,7 +542,7 @@ private Charset determineCharsetFromUnicodeByteOrderMark(final Message message)
} catch (IOException e) {
if (this.summarizeMessageEncodingErrors) {
// TestRun will be invalidated in TestSuite if messageEncodingErrorCount > 0
this.messageEncodingErrorCount += 1;
this.messageEncodingErrorCount.incrementAndGet();
} else {
this.testRunObserver.invalidateTestRun(
"Unable to read message contents of message with ID '" + message.getID() + "'", e);
Expand Down Expand Up @@ -570,7 +571,7 @@ private Charset determineCharsetFromXmlDeclaration(final Message message) {
(String originA, String valueA, String originB, String valueB) -> {
if (this.summarizeMessageEncodingErrors) {
// TestRun will be invalidated in TestSuite if messageEncodingErrorCount > 0
this.messageEncodingErrorCount += 1;
this.messageEncodingErrorCount.incrementAndGet();
} else {
this.testRunObserver.invalidateTestRun(String.format(
INCONSISTENT_CHARSET_DECLARATION_WITH_ORIGINS,
Expand Down Expand Up @@ -736,7 +737,7 @@ private Charset determineCharsetFromHttpHeader(final Message message) {
// the Message before storing it in the DB.
if (this.summarizeMessageEncodingErrors) {
// TestRun will be invalidated in TestSuite if messageEncodingErrorCount > 0
this.messageEncodingErrorCount += 1;
this.messageEncodingErrorCount.incrementAndGet();
} else {
this.testRunObserver.invalidateTestRun(
String.format(
Expand Down Expand Up @@ -1820,7 +1821,7 @@ private void transmit(final List<DatabaseEntry> results) {
* @return the count
*/
public long getMessageEncodingErrorCount() {
return this.messageEncodingErrorCount;
return this.messageEncodingErrorCount.getPlain();
}

/**
Expand All @@ -1832,7 +1833,7 @@ public long getInvalidMimeTypeErrorCount() {
}

/**
* Container for the query result stream and the information on whether or not the objects are present. This shall
* Container for the query result stream and the information on whether the objects are present. This shall
* always be closed after usage!
*
* @param <T> query result stream type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,7 @@ public void testDetermineCharsetFromMessageASCIISpecialCase(@TempDir final File
* @throws IOException - when something goes wrong.
*/
@Test
public void testConvertToMessageContent(@TempDir final File dir) throws IOException {
public void testConvertMessageToMessageContent(@TempDir final File dir) throws IOException {

final Charset charsetInHttpHeader = StandardCharsets.UTF_8;
final Charset charsetInXMLDeclaration = StandardCharsets.UTF_8;
Expand Down Expand Up @@ -2550,12 +2550,13 @@ public void testConvertToMessageContent(@TempDir final File dir) throws IOExcept

// then
assertNotNull(result);
assertFalse(testRunObserver.isInvalid());
assertEquals(content, result.getBody());
verifyNoInteractions(testRunObserver);
}
}

/**
* Checks that convertMessageToMessageContent() works when it does not detect any decoding problems in the message.
* Checks that convertMessageToMessageContent() fails when it detects a decoding problem in the message.
* @param dir - a temporary directory.
* @throws IOException - when something goes wrong.
*/
Expand Down Expand Up @@ -2596,7 +2597,7 @@ public void testConvertToMessageContentFailOnEncodingProblem(@TempDir final File
}

/**
* Checks that convertMessageToMessageContent() works when it does not detect any decoding problems in the message.
* Checks that convertMessageToMessageContent() fails when it detects a decoding problem in the message.
* @param dir - a temporary directory.
* @throws IOException - when something goes wrong.
*/
Expand Down Expand Up @@ -2639,7 +2640,7 @@ public void testConvertToMessageContentFailOnEncodingProblem2(@TempDir final Fil
}

/**
* Checks that convertMessageToMessageContent() works when it does not detect any decoding problems in the message.
* Checks that convertMessageToMessageContent() fails when it detects a decoding problem in the message.
* @param dir - a temporary directory.
* @throws IOException - when something goes wrong.
*/
Expand Down

0 comments on commit 78aa83b

Please sign in to comment.