-
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
- Loading branch information
1 parent
7097ad7
commit cb72274
Showing
5 changed files
with
80 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
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
50 changes: 50 additions & 0 deletions
50
...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,50 @@ | ||
package io.quarkus.narayana.jta.runtime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
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 testByteLengthWithLongerString() { | ||
TransactionManagerConfiguration transactions = new TransactionManagerConfiguration(); | ||
transactions.shortenNodeNameIfNecessary = true; | ||
// create nodeNames larger than 28 bytes | ||
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); | ||
} | ||
|
||
@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); | ||
} | ||
} |