Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jmx/remote/CCAdminReconnectTest.java
38855 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 700999826* @summary Tests the correct processing of concurrent ClientComunicatorAdmin reconnect requests.27* @author Jaroslav Bachorik28* @run clean CCAdminReconnectTest29* @run build CCAdminReconnectTest30* @run main CCAdminReconnectTest31*/3233import com.sun.jmx.remote.internal.ClientCommunicatorAdmin;34import java.io.*;35import java.util.Collection;36import java.util.LinkedList;37import java.util.concurrent.ExecutorService;38import java.util.concurrent.Executors;39import java.util.concurrent.TimeUnit;40import java.util.concurrent.atomic.AtomicBoolean;4142public class CCAdminReconnectTest {43final private static int THREAD_COUNT = 3;4445public static void main(String ... args) throws Exception {46final ExecutorService e = Executors.newFixedThreadPool(THREAD_COUNT);47final AtomicBoolean beingReconnected = new AtomicBoolean();48final Collection<Exception> thrownExceptions = new LinkedList<>();4950System.out.println(": Testing concurrent restart of ClientCommunicatorAdmin");5152final ClientCommunicatorAdmin cca = new ClientCommunicatorAdmin(50) {5354@Override55protected void checkConnection() throws IOException {56// empty57}5859@Override60protected void doStart() throws IOException {61if (!beingReconnected.compareAndSet(false, true)) {62IOException e = new IOException("Detected overlayed reconnect requests");63thrownExceptions.add(e);64throw e;65}66try {67Thread.sleep(800); // simulating a workload68beingReconnected.set(false);69} catch (InterruptedException e) {70}71}7273@Override74protected void doStop() {75// empty76}77};7879Runnable r = new Runnable() {80final private IOException e = new IOException("Forced reconnect");81@Override82public void run() {83try {84// forcing the reconnect request85cca.gotIOException(e);86} catch (Exception ex) {87ex.printStackTrace();88}89}90};9192System.out.println(": Spawning " + THREAD_COUNT + " concurrent reconnect requests");9394for(int i=0;i<THREAD_COUNT;i++) {95e.execute(r);96}9798Thread.sleep(THREAD_COUNT * 1000);99e.shutdown();100e.awaitTermination(10, TimeUnit.SECONDS);101102cca.terminate();103104for(Exception thrown : thrownExceptions) {105throw thrown;106}107System.out.println(": Requests processed successfully");108}109}110111112113