Path: blob/master/test/jdk/com/sun/jmx/remote/CCAdminReconnectTest.java
41153 views
/*1* Copyright (c) 2012, 2015, 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* @modules java.management/com.sun.jmx.remote.internal29* @run clean CCAdminReconnectTest30* @run build CCAdminReconnectTest31* @run main CCAdminReconnectTest32*/3334import com.sun.jmx.remote.internal.ClientCommunicatorAdmin;35import java.io.*;36import java.util.Collection;37import java.util.LinkedList;38import java.util.concurrent.ExecutorService;39import java.util.concurrent.Executors;40import java.util.concurrent.TimeUnit;41import java.util.concurrent.atomic.AtomicBoolean;4243public class CCAdminReconnectTest {44final private static int THREAD_COUNT = 3;4546public static void main(String ... args) throws Exception {47final ExecutorService e = Executors.newFixedThreadPool(THREAD_COUNT);48final AtomicBoolean beingReconnected = new AtomicBoolean();49final Collection<Exception> thrownExceptions = new LinkedList<>();5051System.out.println(": Testing concurrent restart of ClientCommunicatorAdmin");5253final ClientCommunicatorAdmin cca = new ClientCommunicatorAdmin(50) {5455@Override56protected void checkConnection() throws IOException {57// empty58}5960@Override61protected void doStart() throws IOException {62if (!beingReconnected.compareAndSet(false, true)) {63IOException e = new IOException("Detected overlayed reconnect requests");64thrownExceptions.add(e);65throw e;66}67try {68Thread.sleep(800); // simulating a workload69beingReconnected.set(false);70} catch (InterruptedException e) {71}72}7374@Override75protected void doStop() {76// empty77}78};7980Runnable r = new Runnable() {81final private IOException e = new IOException("Forced reconnect");82@Override83public void run() {84try {85// forcing the reconnect request86cca.gotIOException(e);87} catch (Exception ex) {88ex.printStackTrace();89}90}91};9293System.out.println(": Spawning " + THREAD_COUNT + " concurrent reconnect requests");9495for(int i=0;i<THREAD_COUNT;i++) {96e.execute(r);97}9899Thread.sleep(THREAD_COUNT * 1000);100e.shutdown();101e.awaitTermination(10, TimeUnit.SECONDS);102103cca.terminate();104105for(Exception thrown : thrownExceptions) {106throw thrown;107}108System.out.println(": Requests processed successfully");109}110}111112113114