public static ExecutionFailureInfo toFailure(Throwable failure) { return toFailure(failure, newIdentityHashSet()); }
/** * <b>Call {@link Platform#cleanStackTrace} rather than calling this directly.</b> * * <p>Cleans the stack trace on the given {@link Throwable}, replacing the original stack trace * stored on the instance (see {@link Throwable#setStackTrace(StackTraceElement[])}). * * <p>Removes Truth stack frames from the top and JUnit framework and reflective call frames from * the bottom. Collapses the frames for various frameworks in the middle of the trace as well. */ static void cleanStackTrace(Throwable throwable) { new StackTraceCleaner(throwable).clean(Sets.<Throwable>newIdentityHashSet()); }
public void testEntrySet() { Multiset<Color> ms = EnumMultiset.create(Color.class); ms.add(Color.BLUE, 3); ms.add(Color.YELLOW, 1); ms.add(Color.RED, 2); Set<Object> uniqueEntries = Sets.newIdentityHashSet(); uniqueEntries.addAll(ms.entrySet()); assertEquals(3, uniqueEntries.size()); }
public void testEntrySet() { // Bug 3168290 Map<Currency, String> map = ImmutableMap.of( Currency.DOLLAR, "dollar", Currency.PESO, "peso", Currency.FRANC, "franc"); EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(map); Set<Object> uniqueEntries = Sets.newIdentityHashSet(); uniqueEntries.addAll(bimap.entrySet()); assertEquals(3, uniqueEntries.size()); }
public void testNewIdentityHashSet() { Set<Integer> set = Sets.newIdentityHashSet(); Integer value1 = new Integer(12357); Integer value2 = new Integer(12357); assertTrue(set.add(value1)); assertFalse(set.contains(value2)); assertTrue(set.contains(value1)); assertTrue(set.add(value2)); assertEquals(2, set.size()); }
public void testEntrySet() { // Bug 3168290 Map<Currency, Country> map = ImmutableMap.of( Currency.DOLLAR, Country.CANADA, Currency.PESO, Country.CHILE, Currency.FRANC, Country.SWITZERLAND); EnumBiMap<Currency, Country> bimap = EnumBiMap.create(map); Set<Object> uniqueEntries = Sets.newIdentityHashSet(); uniqueEntries.addAll(bimap.entrySet()); assertEquals(3, uniqueEntries.size()); }
void checkIterator(LinkedDeque<E> deque, Iterator<E> iterator, DescriptionBuilder desc) { Set<E> seen = Sets.newIdentityHashSet(); while (iterator.hasNext()) { E element = iterator.next(); checkElement(deque, element, desc); Supplier<String> errorMsg = () -> String.format("Loop detected: %s in %s", element, seen); desc.expectThat(errorMsg, seen.add(element), is(true)); } desc.expectThat("deque size", deque, hasSize(seen.size())); }
Set<LockGraphNode> seen = Sets.newIdentityHashSet(); ExampleStackTrace path = acquiredLock.findPathTo(this, seen);
!context.mapJoinToUnprocessedSmallTableReduceSinks.containsKey(mapJoinOp)) { Set<ReduceSinkOperator> rsSet = Sets.newIdentityHashSet(); for (int pos = 0; pos < mapJoinOp.getParentOperators().size(); ++pos) { if (pos == mapJoinOp.getConf().getPosBigTable()) {
void checkForLoop(SingleConsumerQueue<E> queue, DescriptionBuilder builder) { builder.expectThat("Expected sentinel node", queue.head.value, is(nullValue())); Set<Node<E>> seen = Sets.newIdentityHashSet(); Node<E> node = queue.head.next; while (node != null) { Node<E> current = node; Supplier<String> errorMsg = () -> String.format("Loop detected: %s in %s", current, seen); builder.expectThat(errorMsg, seen.add(node), is(true)); builder.expectThat("not tail", node, is(not(queue.head))); builder.expectThat("not completed", node.isDone(), is(true)); builder.expectThat("not null value", node.value, is(not(nullValue()))); node = node.next; } builder.expectThat("queue size", queue, hasSize(seen.size())); }
Set<LockGraphNode> seen = Sets.newIdentityHashSet(); ExampleStackTrace path = acquiredLock.findPathTo(this, seen);
@Test public void testSparkThreadLocal() throws Exception { // Test that input name does not change IOContext returned, and that each thread gets its own. final Configuration conf1 = new Configuration(); conf1.set(HiveConf.ConfVars.HIVE_EXECUTION_ENGINE.varname, "spark"); final Configuration conf2 = new Configuration(conf1); conf2.set(Utilities.INPUT_NAME, "Other input"); final int THREAD_COUNT = 2; ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT); final CountDownLatch cdlIn = new CountDownLatch(THREAD_COUNT), cdlOut = new CountDownLatch(1); @SuppressWarnings("unchecked") FutureTask<IOContext>[] tasks = new FutureTask[THREAD_COUNT]; for (int i = 0; i < tasks.length; ++i) { tasks[i] = new FutureTask<IOContext>(new Callable<IOContext>() { public IOContext call() throws Exception { syncThreadStart(cdlIn, cdlOut); IOContext c1 = IOContextMap.get(conf1), c2 = IOContextMap.get(conf2); assertSame(c1, c2); return c1; } }); executor.execute(tasks[i]); } cdlIn.await(); // Wait for all threads to be ready. cdlOut.countDown(); // Release them at the same time. Set<IOContext> results = Sets.newIdentityHashSet(); for (int i = 0; i < tasks.length; ++i) { assertTrue(results.add(tasks[i].get())); // All the objects must be different. } }
final Set<Object> finalResults = Collections.synchronizedSet(Sets.newIdentityHashSet()); final Runnable collectResultsRunnable = new Runnable() {
tasks[i].get(); Set<IOContext> resultSet = Sets.newIdentityHashSet(); for (int i = 0; i < results.length; ++i) {
final Set<Object> finalResults = Collections.synchronizedSet(Sets.newIdentityHashSet()); Runnable collectResultsRunnable = new Runnable() {
final Set<Object> finalResults = Collections.synchronizedSet(Sets.newIdentityHashSet()); Runnable collectResultsRunnable = new Runnable() {
static void checkExpiration(LocalCache<?, ?> cchm) { for (Segment<?, ?> segment : cchm.segments) { if (cchm.usesWriteQueue()) { Set<ReferenceEntry<?, ?>> entries = Sets.newIdentityHashSet(); Set<ReferenceEntry<?, ?>> entries = Sets.newIdentityHashSet();
private void checkLinks(BoundedLocalCache<K, V> cache, ImmutableList<LinkedDeque<Node<K, V>>> deques, DescriptionBuilder desc) { int size = 0; long weightedSize = 0; Set<Node<K, V>> seen = Sets.newIdentityHashSet(); for (LinkedDeque<Node<K, V>> deque : deques) { size += deque.size(); weightedSize += scanLinks(cache, seen, deque, desc); } if (cache.size() != size) { desc.expectThat(() -> "deque size " + deques, size, is(cache.size())); } Supplier<String> errorMsg = () -> String.format( "Size != list length; pending=%s, additional: %s", cache.writeBuffer().size(), Sets.difference(seen, ImmutableSet.copyOf(cache.data.values()))); desc.expectThat(errorMsg, cache.size(), is(seen.size())); final long weighted = weightedSize; if (cache.evicts()) { Supplier<String> error = () -> String.format( "WeightedSize != link weights [%d vs %d] {%d vs %d}", cache.adjustedWeightedSize(), weighted, seen.size(), cache.size()); desc.expectThat("non-negative weight", weightedSize, is(greaterThanOrEqualTo(0L))); desc.expectThat(error, cache.adjustedWeightedSize(), is(weightedSize)); } }
private static void assertBasicInvariants(Striped<?> striped) { Set<Object> observed = Sets.newIdentityHashSet(); // for the sake of weakly referenced locks. // this gets the stripes with #getAt(index) for (int i = 0; i < striped.size(); i++) { Object object = striped.getAt(i); assertNotNull(object); assertSame(object, striped.getAt(i)); // idempotent observed.add(object); } assertTrue("All stripes observed", observed.size() == striped.size()); // this uses #get(key), makes sure an already observed stripe is returned for (int i = 0; i < striped.size() * 100; i++) { assertTrue(observed.contains(striped.get(new Object()))); } try { striped.getAt(-1); fail(); } catch (RuntimeException expected) { } try { striped.getAt(striped.size()); fail(); } catch (RuntimeException expected) { } }
private void checkTimerWheel(BoundedLocalCache<K, V> cache) { if (!cache.expiresVariable()) { return; } Set<Node<K, V>> seen = Sets.newIdentityHashSet(); for (int i = 0; i < cache.timerWheel().wheel.length; i++) { for (int j = 0; j < cache.timerWheel().wheel[i].length; j++) { Node<K, V> sentinel = cache.timerWheel().wheel[i][j]; desc.expectThat("Wrong sentinel prev", sentinel.getPreviousInVariableOrder().getNextInVariableOrder(), sameInstance(sentinel)); desc.expectThat("Wrong sentinel next", sentinel.getNextInVariableOrder().getPreviousInVariableOrder(), sameInstance(sentinel)); desc.expectThat("Sentinel must be first element", sentinel, instanceOf(Sentinel.class)); for (Node<K, V> node = sentinel.getNextInVariableOrder(); node != sentinel; node = node.getNextInVariableOrder()) { Node<K, V> next = node.getNextInVariableOrder(); Node<K, V> prev = node.getPreviousInVariableOrder(); long duration = node.getVariableTime() - cache.timerWheel().nanos; desc.expectThat("Expired", duration, greaterThan(0L)); desc.expectThat("Loop detected", seen.add(node), is(true)); desc.expectThat("Wrong prev", prev.getNextInVariableOrder(), is(sameInstance(node))); desc.expectThat("Wrong next", next.getPreviousInVariableOrder(), is(sameInstance(node))); } } } desc.expectThat("Timers != Entries", seen, hasSize(cache.size())); }