-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node-name needs to be truncated because the byte array is not base64
Add unit test, stress test commented and updated the JavaDoc
- Loading branch information
1 parent
eb49de2
commit ed0d407
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...na-jta/runtime/src/test/java/io/quarkus/narayana/jta/runtime/NarayanaJtaRecorderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.quarkus.narayana.jta.runtime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class NarayanaJtaRecorderTest { | ||
|
||
@Test | ||
void testByteLength() { | ||
TransactionManagerConfiguration transactions = new TransactionManagerConfiguration(); | ||
transactions.shortenNodeNameIfNecessary = true; | ||
// create nodeNames larger than 28 bytes | ||
for (int i = 1; i < 100; i++) { | ||
String originalNodeName = UUID.randomUUID().toString(); | ||
NarayanaJtaRecorder r = new NarayanaJtaRecorder(); | ||
transactions.nodeName = originalNodeName; | ||
r.setNodeName(transactions); | ||
int numberOfBytes = transactions.nodeName.getBytes(StandardCharsets.UTF_8).length; | ||
assertFalse(numberOfBytes > 28, | ||
"node name bytes still exceeded 28 bytes limit, number of bytes is " + numberOfBytes); | ||
} | ||
for (int i = 1; i < 1000; i++) { | ||
byte[] data = new byte[i]; | ||
NarayanaJtaRecorder r = new NarayanaJtaRecorder(); | ||
transactions.nodeName = new String(data); | ||
r.setNodeName(transactions); | ||
int numberOfBytes = transactions.nodeName.getBytes(StandardCharsets.UTF_8).length; | ||
assertFalse(numberOfBytes > 28, | ||
"node name bytes still exceeded 28 bytes limit, number of bytes is " + numberOfBytes); | ||
} | ||
} | ||
|
||
//commented because it is a stress test | ||
// @Test | ||
void testCollision() { | ||
SortedSet<String> set = new TreeSet<>(); | ||
TransactionManagerConfiguration transactions = new TransactionManagerConfiguration(); | ||
transactions.shortenNodeNameIfNecessary = true; | ||
// create a nodeName larger than 28 bytes | ||
for (int i = 1; i < 1000000; i++) { | ||
String originalNodeName = UUID.randomUUID().toString(); | ||
NarayanaJtaRecorder r = new NarayanaJtaRecorder(); | ||
transactions.nodeName = originalNodeName; | ||
r.setNodeName(transactions); | ||
assertFalse(set.contains(transactions.nodeName), "Collision of IDs for " + transactions.nodeName); | ||
set.add(transactions.nodeName); | ||
} | ||
} | ||
|
||
} |