Skip to content

Navigation Menu

Sign in
Sign up

Fix #7855: testlib: add tests for ConcurrentMap to make sure its derived Sets are concurrent #8599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Himan-D wants to merge 2 commits into google:master
base: master
Choose a base branch
Loading
from Himan-D:fix-concurrent-map-spliterator
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
ConcurrentMapPutIfAbsentTester.class,
ConcurrentMapRemoveTester.class,
ConcurrentMapReplaceTester.class,
ConcurrentMapReplaceEntryTester.class);
ConcurrentMapReplaceEntryTester.class,
ConcurrentMapSpliteratorTester.class);

Check failure on line 48 in guava-testlib/src/com/google/common/collect/testing/ConcurrentMapTestSuiteBuilder.java

View workflow job for this annotation

GitHub Actions / pom.xml on JDK 11 on ubuntu-latest

cannot find symbol

Check failure on line 48 in guava-testlib/src/com/google/common/collect/testing/ConcurrentMapTestSuiteBuilder.java

View workflow job for this annotation

GitHub Actions / pom.xml on JDK 11 on ubuntu-latest

cannot find symbol

Check failure on line 48 in guava-testlib/src/com/google/common/collect/testing/ConcurrentMapTestSuiteBuilder.java

View workflow job for this annotation

GitHub Actions / pom.xml on JDK 25 on ubuntu-latest

cannot find symbol

Check failure on line 48 in guava-testlib/src/com/google/common/collect/testing/ConcurrentMapTestSuiteBuilder.java

View workflow job for this annotation

GitHub Actions / pom.xml on JDK 25 on ubuntu-latest

cannot find symbol

Check failure on line 48 in guava-testlib/src/com/google/common/collect/testing/ConcurrentMapTestSuiteBuilder.java

View workflow job for this annotation

GitHub Actions / pom.xml on JDK 17 on ubuntu-latest

cannot find symbol

Check failure on line 48 in guava-testlib/src/com/google/common/collect/testing/ConcurrentMapTestSuiteBuilder.java

View workflow job for this annotation

GitHub Actions / pom.xml on JDK 17 on ubuntu-latest

cannot find symbol

Check failure on line 48 in guava-testlib/src/com/google/common/collect/testing/ConcurrentMapTestSuiteBuilder.java

View workflow job for this annotation

GitHub Actions / pom.xml on JDK 8 on ubuntu-latest

cannot find symbol

Check failure on line 48 in guava-testlib/src/com/google/common/collect/testing/ConcurrentMapTestSuiteBuilder.java

View workflow job for this annotation

GitHub Actions / pom.xml on JDK 8 on ubuntu-latest

cannot find symbol

@SuppressWarnings("rawtypes") // class literals
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2026 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.common.collect.testing.testers;

import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.testing.AbstractMapTester;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Spliterator;
import java.util.stream.Stream;

@GwtIncompatible
public class ConcurrentMapSpliteratorTester<K, V> extends AbstractMapTester<K, V> {

public void testKeySetSpliterator() {
Spliterator<K> spliterator = getMap().keySet().spliterator();
assertTrue(
"keySet spliterator should be CONCURRENT",
spliterator.hasCharacteristics(Spliterator.CONCURRENT));
assertFalse(
"keySet spliterator should not be SIZED",
spliterator.hasCharacteristics(Spliterator.SIZED));
testStreamToList(getMap().keySet().stream());
}

public void testValuesSpliterator() {
Spliterator<V> spliterator = getMap().values().spliterator();
assertTrue(
"values spliterator should be CONCURRENT",
spliterator.hasCharacteristics(Spliterator.CONCURRENT));
assertFalse(
"values spliterator should not be SIZED",
spliterator.hasCharacteristics(Spliterator.SIZED));
testStreamToList(getMap().values().stream());
}

public void testEntrySetSpliterator() {
Spliterator<java.util.Map.Entry<K, V>> spliterator = getMap().entrySet().spliterator();
assertTrue(
"entrySet spliterator should be CONCURRENT",
spliterator.hasCharacteristics(Spliterator.CONCURRENT));
assertFalse(
"entrySet spliterator should not be SIZED",
spliterator.hasCharacteristics(Spliterator.SIZED));
testStreamToList(getMap().entrySet().stream());
}

private void testStreamToList(Stream<?> stream) {
try {
Method toList = Stream.class.getMethod("toList");
List<?> list = (List<?>) toList.invoke(stream);
assertEquals(getNumElements(), list.size());
} catch (NoSuchMethodException e) {
// Stream.toList() not available, just check toArray
assertEquals(getNumElements(), stream.toArray().length);
} catch (Exception e) {
fail("Stream.toList() threw exception: " + e.getCause());
}
}
}
Loading

AltStyle によって変換されたページ (->オリジナル) /