Skip to content

UUID.randomUUID uses cryptographically strong pseudo random number generator which might cause slowness when executing tests #3219

@vlsi

Description

@vlsi

Currently, testng uses UUID.randomUUID multiple times, and I do not think it really requires cryptographic strength: https://github.com/search?q=repo%3Atestng-team%2Ftestng%20randomUUID&type=code

There was an attempt to make UUID.randomUUID more scalable, however, it has not been integrated yet: https://bugs.openjdk.org/browse/JDK-8308804

I would suggest replacing UUID.randomUUID with a variation that generates random out of ThreadLocalRandom.

Something like

      ThreadLocalRandom rnd = ThreadLocalRandom.current();
      return new UUID(
          (rnd.nextLong() & ~0xF000L) | 0x4000L, // set version to 4
          rnd.nextLong() & ~(3L << 62) | (2L << 62) // set variant to 10
      );

It would generate good-enough UUIDs without paying too much for the cryptographic random generator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions