forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eee79e1
commit 24cbd0f
Showing
1 changed file
with
36 additions
and
20 deletions.
There are no files selected for viewing
56 changes: 36 additions & 20 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 |
---|---|---|
@@ -1,37 +1,53 @@ | ||
package io.quarkus.narayana.jta.runtime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class NarayanaJtaRecorderTest { | ||
|
||
//this string has been chosen as when hashed and Base64 encoded the resulted byte array will have a length > 28, so it will be trimmed too. | ||
public static final String NODE_NAME_TO_SHORTEN = "dfe2420d-b12e-4ec3-92c0-ee7c4"; | ||
|
||
@Test | ||
void testByteLength() { | ||
void testByteLengthWithLongerString() { | ||
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); | ||
} | ||
assertTrue(NODE_NAME_TO_SHORTEN.getBytes(StandardCharsets.UTF_8).length > 28); | ||
NarayanaJtaRecorder r = new NarayanaJtaRecorder(); | ||
transactions.nodeName = NODE_NAME_TO_SHORTEN; | ||
r.setNodeName(transactions); | ||
int numberOfBytes = transactions.nodeName.getBytes(StandardCharsets.UTF_8).length; | ||
assertEquals(28, numberOfBytes, | ||
"node name bytes was not 28 bytes limit, number of bytes is " + numberOfBytes); | ||
assertFalse(numberOfBytes > 28, | ||
"node name bytes still exceeded 28 bytes limit, number of bytes is " + numberOfBytes); | ||
} | ||
|
||
@Test | ||
void testPredictableConversion() { | ||
TransactionManagerConfiguration transactions = new TransactionManagerConfiguration(); | ||
transactions.shortenNodeNameIfNecessary = true; | ||
assertTrue(NODE_NAME_TO_SHORTEN.getBytes(StandardCharsets.UTF_8).length > 28); | ||
NarayanaJtaRecorder r = new NarayanaJtaRecorder(); | ||
transactions.nodeName = NODE_NAME_TO_SHORTEN; | ||
r.setNodeName(transactions); | ||
int numberOfBytes = transactions.nodeName.getBytes(StandardCharsets.UTF_8).length; | ||
assertEquals(28, numberOfBytes, | ||
"node name bytes was not 28 bytes limit, number of bytes is " + numberOfBytes); | ||
String firstConversion = transactions.nodeName; | ||
transactions.nodeName = NODE_NAME_TO_SHORTEN; | ||
r.setNodeName(transactions); | ||
String secondConversion = transactions.nodeName; | ||
numberOfBytes = transactions.nodeName.getBytes(StandardCharsets.UTF_8).length; | ||
assertEquals(28, numberOfBytes, | ||
"node name bytes was not 28 bytes limit, number of bytes is " + numberOfBytes); | ||
assertEquals(firstConversion, secondConversion, | ||
"Node names were shortened differently: " + firstConversion + " " + secondConversion); | ||
} | ||
} |