Code example for Random

Methods: nextBytes, nextInt

0
public class TransactionIdUnitTest { 
    private final Random rand = new Random();
 
 
    private byte[] randomBytes() { 
        final byte[] bytes = new byte[this.rand.nextInt(100)];
        this.rand.nextBytes(bytes);
        return bytes;
    } 
 
 
    @Test 
    public void testValueOf() { 
        final byte[] branchQualifier = this.randomBytes();
        final byte[] globalTransactionId = this.randomBytes();
        final XATransactionId xid = new XATransactionId(100, branchQualifier, globalTransactionId, "unique-qualifier");
        final LocalTransactionId id = new LocalTransactionId("sessionId", -99);
 
        final String key1 = xid.getTransactionKey();
        final String key2 = id.getTransactionKey();