Tabnine Logo
TraceAndSpanIdGenerator.getRandomInstance
Code IndexAdd Tabnine to your IDE (free)

How to use
getRandomInstance
method
in
com.nike.wingtips.TraceAndSpanIdGenerator

Best Java code snippets using com.nike.wingtips.TraceAndSpanIdGenerator.getRandomInstance (Showing top 2 results out of 315)

origin: Nike-Inc/wingtips

@Test
public void getRandomInstance_should_default_to_normal_random_if_desired_algorithm_is_not_available() {
  Random randomGenerator = TraceAndSpanIdGenerator.getRandomInstance("QuantumDoohickey");
  assertThat(randomGenerator).isNotNull();
  assertThat(randomGenerator).isNotInstanceOf(SecureRandom.class);
}
origin: Nike-Inc/wingtips

@Test
public void getRandomInstance_should_return_requested_instance_if_available() {
  // given: all available SecureRandom algorithm providers
  Provider[] availableProviders = Security.getProviders();
  assertThat(availableProviders).isNotNull();
  assertThat(availableProviders.length).isGreaterThanOrEqualTo(1);
  // Ignore some algorithms because they fail on OSX if you're not an admin.
  // We don't care that *all* algorithms are available at all times on all platforms, just that the code does what it's supposed to do.
  List<String> excludedAlgorithms = Collections.singletonList("NativePRNGNonBlocking");
  Set<String> availableSecureRandomAlgorithms = new HashSet<>();
  for (Provider provider : availableProviders) {
    Set<Provider.Service> services = provider.getServices();
    for (Provider.Service service : services) {
      String type = service.getType();
      if ("SecureRandom".equals(type) && !excludedAlgorithms.contains(service.getAlgorithm()))
        availableSecureRandomAlgorithms.add(service.getAlgorithm());
    }
  }
  assertThat(availableSecureRandomAlgorithms).isNotEmpty();
  for (String algorithm : availableSecureRandomAlgorithms) {
    // when: we ask getRandomInstance for the algorithm
    Random randomGenerator = TraceAndSpanIdGenerator.getRandomInstance(algorithm);
    // then: we get back a valid SecureRandom that uses the requested algorithm
    assertThat(randomGenerator).isNotNull();
    assertThat(randomGenerator).isInstanceOf(SecureRandom.class);
    //noinspection ConstantConditions
    assertThat(((SecureRandom)randomGenerator).getAlgorithm()).isEqualTo(algorithm);
  }
}
com.nike.wingtipsTraceAndSpanIdGeneratorgetRandomInstance

Javadoc

Tries to retrieve and return the SecureRandom with the given implementation using SecureRandom#getInstance(String), and falls back to a new Random(System.nanoTime()) if that instance could not be found.

Popular methods of TraceAndSpanIdGenerator

  • generateId
  • longToUnsignedLowerHexString
  • unsignedLowerHexStringToLong
  • convertBytesToLong
    Converts the given 8 bytes to a long value. Implementation for this taken from java.util.UUID#UUID(b
  • generate64BitRandomLong

Popular in Java

  • Start an intent from android
  • compareTo (BigDecimal)
  • getResourceAsStream (ClassLoader)
  • getExternalFilesDir (Context)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • JFrame (javax.swing)
  • JLabel (javax.swing)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now