Tabnine Logo
PredicateWithTracing
Code IndexAdd Tabnine to your IDE (free)

How to use
PredicateWithTracing
in
com.nike.wingtips.util.asynchelperwrapper

Best Java code snippets using com.nike.wingtips.util.asynchelperwrapper.PredicateWithTracing (Showing top 12 results out of 315)

origin: Nike-Inc/wingtips

/**
 * @return A {@link Predicate} that wraps the given original so that the given distributed tracing and MDC
 * information is registered with the thread and therefore available during execution and unregistered after
 * execution.
 */
default <T> Predicate<T> predicateWithTracing(Predicate<T> predicate,
                       Deque<Span> spanStackToLink,
                       Map<String, String> mdcContextMapToLink) {
  return new PredicateWithTracing<>(predicate, spanStackToLink, mdcContextMapToLink);
}
origin: Nike-Inc/wingtips

@Test
public void constructors_throw_exception_if_passed_null_operator() {
  // given
  final Deque<Span> spanStackMock = mock(Deque.class);
  final Map<String, String> mdcInfoMock = mock(Map.class);
  // expect
  assertThat(catchThrowable(() -> new PredicateWithTracing(null)))
    .isInstanceOf(IllegalArgumentException.class);
  assertThat(catchThrowable(() -> withTracing(null)))
    .isInstanceOf(IllegalArgumentException.class);
  // and expect
  assertThat(catchThrowable(() -> new PredicateWithTracing(null, Pair.of(spanStackMock, mdcInfoMock))))
    .isInstanceOf(IllegalArgumentException.class);
  assertThat(catchThrowable(() -> withTracing(null, Pair.of(spanStackMock, mdcInfoMock))))
    .isInstanceOf(IllegalArgumentException.class);
  // and expect
  assertThat(catchThrowable(() -> new PredicateWithTracing(null, spanStackMock, mdcInfoMock)))
    .isInstanceOf(IllegalArgumentException.class);
  assertThat(catchThrowable(() -> withTracing(null, spanStackMock, mdcInfoMock)))
    .isInstanceOf(IllegalArgumentException.class);
}
origin: Nike-Inc/wingtips

Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
PredicateWithTracing instance = new PredicateWithTracing(
  predicateMock, spanStack, mdcInfo
);
Boolean result = null;
try {
  result = instance.test(inObj);
origin: Nike-Inc/wingtips

@DataProvider(value = {
  "true",
  "false"
})
@Test
public void pair_constructor_sets_fields_as_expected_when_pair_is_null(boolean useStaticFactory) {
  // when
  PredicateWithTracing instance = (useStaticFactory)
                   ? withTracing(predicateMock, (Pair)null)
                   : new PredicateWithTracing(predicateMock, (Pair)null);
  // then
  assertThat(instance.origPredicate).isSameAs(predicateMock);
  assertThat(instance.spanStackForExecution).isNull();
  assertThat(instance.mdcContextMapForExecution).isNull();
}
origin: Nike-Inc/wingtips

@DataProvider(value = {
  "true",
  "false"
})
@Test
public void kitchen_sink_constructor_sets_fields_as_expected(boolean useStaticFactory) {
  // given
  Deque<Span> spanStackMock = mock(Deque.class);
  Map<String, String> mdcInfoMock = mock(Map.class);
  // when
  PredicateWithTracing instance = (useStaticFactory)
                   ? withTracing(predicateMock, spanStackMock, mdcInfoMock)
                   : new PredicateWithTracing(predicateMock, spanStackMock, mdcInfoMock);
  // then
  assertThat(instance.origPredicate).isSameAs(predicateMock);
  assertThat(instance.spanStackForExecution).isEqualTo(spanStackMock);
  assertThat(instance.mdcContextMapForExecution).isEqualTo(mdcInfoMock);
}
origin: Nike-Inc/wingtips

/**
 * @return A {@link Predicate} that wraps the given original so that the given distributed tracing and MDC
 * information is registered with the thread and therefore available during execution and unregistered after
 * execution. You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 */
default <T> Predicate<T> predicateWithTracing(Predicate<T> predicate,
                       Pair<Deque<Span>, Map<String, String>> threadInfoToLink) {
  return new PredicateWithTracing<>(predicate, threadInfoToLink);
}
origin: Nike-Inc/wingtips

@DataProvider(value = {
  "true   |   true    |   true",
  "true   |   false   |   true",
  "false  |   true    |   true",
  "false  |   false   |   true",
  "true   |   true    |   false",
  "true   |   false   |   false",
  "false  |   true    |   false",
  "false  |   false   |   false",
}, splitBy = "\\|")
@Test
public void pair_constructor_sets_fields_as_expected(
  boolean nullSpanStack, boolean nullMdcInfo, boolean useStaticFactory
) {
  // given
  Deque<Span> spanStackMock = (nullSpanStack) ? null : mock(Deque.class);
  Map<String, String> mdcInfoMock = (nullMdcInfo) ? null : mock(Map.class);
  // when
  PredicateWithTracing instance = (useStaticFactory)
                   ? withTracing(predicateMock, Pair.of(spanStackMock, mdcInfoMock))
                   : new PredicateWithTracing(predicateMock, Pair.of(spanStackMock, mdcInfoMock)
                   );
  // then
  assertThat(instance.origPredicate).isSameAs(predicateMock);
  assertThat(instance.spanStackForExecution).isEqualTo(spanStackMock);
  assertThat(instance.mdcContextMapForExecution).isEqualTo(mdcInfoMock);
}
origin: Nike-Inc/wingtips

/**
 * @return A {@link Predicate} that wraps the given original so that the <b>current thread's</b> tracing and MDC
 * information is registered with the thread and therefore available during execution and unregistered after
 * execution.
 *
 * <p>NOTE: The current thread's tracing and MDC info will be extracted using {@link
 * Tracer#getCurrentSpanStackCopy()} and {@link MDC#getCopyOfContextMap()}.
 */
default <T> Predicate<T> predicateWithTracing(Predicate<T> predicate) {
  return new PredicateWithTracing<>(predicate);
}
origin: Nike-Inc/wingtips

@DataProvider(value = {
  "true",
  "false"
})
@Test
public void current_thread_info_constructor_sets_fields_as_expected(boolean useStaticFactory) {
  // given
  Tracer.getInstance().startRequestWithRootSpan("request-" + UUID.randomUUID().toString());
  Deque<Span> spanStackMock = Tracer.getInstance().getCurrentSpanStackCopy();
  Map<String, String> mdcInfoMock = MDC.getCopyOfContextMap();
  // when
  PredicateWithTracing instance = (useStaticFactory)
                   ? withTracing(predicateMock)
                   : new PredicateWithTracing(predicateMock);
  // then
  assertThat(instance.origPredicate).isSameAs(predicateMock);
  assertThat(instance.spanStackForExecution).isEqualTo(spanStackMock);
  assertThat(instance.mdcContextMapForExecution).isEqualTo(mdcInfoMock);
}
origin: Nike-Inc/wingtips

/**
 * Equivalent to calling {@code new PredicateWithTracing(origPredicate)} - this allows you to do a static method
 * import for cleaner looking code in some cases. This method ultimately extracts the current tracing and MDC
 * information from the current thread using {@link Tracer#getCurrentSpanStackCopy()} and {@link
 * MDC#getCopyOfContextMap()}. That tracing and MDC information will be associated with the thread when the given
 * operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * @return {@code new PredicateWithTracing(origPredicate)}.
 * @see PredicateWithTracing#PredicateWithTracing(Predicate)
 * @see PredicateWithTracing
 */
public static <T> PredicateWithTracing<T> withTracing(Predicate<T> origPredicate) {
  return new PredicateWithTracing<>(origPredicate);
}
origin: Nike-Inc/wingtips

/**
 * Equivalent to calling {@code
 * new PredicateWithTracing(origPredicate, spanStackForExecution, mdcContextMapForExecution)} -
 * this allows you to do a static method import for cleaner looking code in some cases. This method uses the given
 * trace and MDC information, which will be associated with the thread when the given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The trace and/or MDC info can be null and no error will be thrown, however any trace or MDC info that is null
 * means the corresponding info will not be available to the thread when the operation is executed.
 *
 * @return {@code new PredicateWithTracing(origPredicate, spanStackForExecution, mdcContextMapForExecution)}.
 * @see PredicateWithTracing#PredicateWithTracing(Predicate, Deque, Map)
 * @see PredicateWithTracing
 */
public static <T> PredicateWithTracing<T> withTracing(Predicate<T> origPredicate,
                           Deque<Span> spanStackForExecution,
                           Map<String, String> mdcContextMapForExecution) {
  return new PredicateWithTracing<>(origPredicate, spanStackForExecution, mdcContextMapForExecution);
}
origin: Nike-Inc/wingtips

/**
 * Equivalent to calling {@code new PredicateWithTracing(origPredicate, originalThreadInfo)} - this allows you
 * to do a static method import for cleaner looking code in some cases. This method uses the given trace and MDC
 * information, which will be associated with the thread when the given operation is executed.
 *
 * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in
 * null for the operation).
 *
 * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error
 * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the
 * thread when the operation is executed however.
 *
 * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends
 * {@code Pair<Deque<Span>, Map<String, String>>}.
 *
 * @return {@code new PredicateWithTracing(origPredicate, originalThreadInfo)}.
 * @see PredicateWithTracing#PredicateWithTracing(Predicate, Pair)
 * @see PredicateWithTracing
 */
public static <T> PredicateWithTracing<T> withTracing(Predicate<T> origPredicate,
                           Pair<Deque<Span>, Map<String, String>> originalThreadInfo) {
  return new PredicateWithTracing<>(origPredicate, originalThreadInfo);
}
com.nike.wingtips.util.asynchelperwrapperPredicateWithTracing

Javadoc

A Predicate that wraps the given original so that the given distributed tracing and MDC information is registered with the thread and therefore available during execution and unregistered after execution.

Most used methods

  • <init>
    Constructor that uses the given trace and MDC information, which will be associated with the thread
  • test
  • withTracing
    Equivalent to calling new PredicateWithTracing(origPredicate, spanStackForExecution, mdcContextMapFo

Popular in Java

  • Start an intent from android
  • getSupportFragmentManager (FragmentActivity)
  • onCreateOptionsMenu (Activity)
  • getContentResolver (Context)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Top plugins for WebStorm
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