public void testRandomAccessDecryption(
      StreamingAead stream, byte[] associatedData, int plaintextSize) throws Exception {
    int numberOfReads = 128;
    int numberOfThreads = 10;
    byte[] plaintext = new byte[plaintextSize];
    for (int i = 0; i < plaintextSize; i++) {
      // Setting plaintex[i] to (byte) i, allows the decrypting thread to check that the
      // plaintext is from a continuous part of the plaintext.
      plaintext[i] = (byte) i;
    }
    byte[] ciphertext = encrypt(stream, plaintext, associatedData);
    SeekableByteChannel ctChannel = new SeekableByteBufferChannel(ciphertext);
    SeekableByteChannel decChannel = stream.newSeekableDecryptingChannel(ctChannel, associatedData);

    ExceptionHandler exceptionHandler = new ExceptionHandler();
    Thread[] thread = new Thread[numberOfThreads];
    for (int i = 0; i < numberOfThreads; i++) {
      thread[i] = new RandomAccessThread(decChannel, plaintextSize, numberOfReads);
      thread[i].setUncaughtExceptionHandler(exceptionHandler);
    }
    for (int i = 0; i < numberOfThreads; i++) {
      thread[i].start();
    }
    for (int i = 0; i < numberOfThreads; i++) {
      thread[i].join();
    }
    exceptionHandler.check();
  }
Test for thread safety using SeekableByteChannels. This test is an incorrect use case for
StreamingAead implementations, since SeekableByteChannels can't be used in multiple threads.
I.e. an implementation cannot guarantee that no other thread modifies the stream between a call
to SeekableByteChannel.position(long) and SeekableByteChannel.read(ByteBuffer). Therefore, the
test here only checks whether the operations are atomic. E.g. a read should read contiuous
bytes.
java_src/src/test/java/com/google/crypto/tink/subtle/StreamingAeadThreadSafetyTest.java