Skip to content

Commit

Permalink
Whitelist ConcurrentHashMap#initTable (#34)
Browse files Browse the repository at this point in the history
* Whitelist `ConcurrentHashMap#initTable`

* Add the license header
  • Loading branch information
bsideup authored Jun 10, 2019
1 parent af6e0c9 commit 6766234
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions agent/src/main/java/reactor/blockhound/BlockHound.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -148,6 +149,10 @@ public static class Builder {
put(Throwable.class, new HashMap<String, Boolean>() {{
put("printStackTrace", true);
}});

put(ConcurrentHashMap.class, new HashMap<String, Boolean>() {{
put("initTable", true);
}});
}};

private Consumer<BlockingMethod> onBlockingMethod = method -> {
Expand Down
44 changes: 44 additions & 0 deletions example/src/test/java/com/example/JDKTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2019-Present Pivotal Software Inc, All Rights Reserved.
*
* 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
*
* https://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.example;

import org.junit.Test;
import reactor.blockhound.BlockHound;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;

import java.util.concurrent.ConcurrentHashMap;

public class JDKTest {

static {
BlockHound.install();
}

@Test
public void shouldAllowConcurrentHashMapInit() {
for (int i = 0; i < 100; i++) {
var map = new ConcurrentHashMap<Integer, Boolean>();
Flux.range(0, Runtime.getRuntime().availableProcessors())
.parallel()
.runOn(Schedulers.parallel())
.doOnNext(it -> map.put(it, true))
.sequential()
.blockLast();
}
}
}

0 comments on commit 6766234

Please sign in to comment.