Beispiel #1
0
 private static synchronized void kill() {
   if (sessionList != null) {
     for (HTTPSession session : sessionList) {
       session.close();
     }
     sessionList.clear();
     // Rebuild the connection manager
     connmgr.shutdown();
     connmgr = new MultiThreadedHttpConnectionManager();
     setGlobalThreadCount(DFALTTHREADCOUNT);
   }
 }
 /** Stop all the threads and stuff used for this config. */
 public synchronized void close() {
   try {
     WMSServerInfo.clearCache();
   } finally {
     try {
       if (mapRenderingExecutor != null) {
         mapRenderingExecutor.stop();
       }
     } finally {
       if (connectionManager != null) {
         connectionManager.shutdown();
       }
     }
   }
 }
  @PreDestroy
  public void stop() {
    eventWorker.stop();
    eventWorkerThread.interrupt();
    try {
      Logs.logThreadJoin(eventWorkerThread);
      eventWorkerThread.join();
    } catch (InterruptedException e) {
      log.info("Interrupted while joining eventWorkerThread.");
    }

    for (IndexUpdaterHandle handle : indexUpdaters.values()) {
      try {
        handle.stop();
      } catch (InterruptedException e) {
        // Continue the stop procedure
      }
    }

    connectionManager.shutdown();
  }
Beispiel #4
0
  public void run() {

    fLogger.info("Initiating testCase " + fTestCase.getName());

    fServer.startTest(this);

    List<Thread> threads = new ArrayList<Thread>();
    boolean measureTestcoverage = BPELUnitRunner.measureTestCoverage();
    if (measureTestcoverage) {
      BPELUnitRunner.getCoverageMeasurmentTool().setCurrentTestCase(fTestCase.getName());
    }
    for (PartnerTrack partnerTrack : fPartnerTracks.keySet()) {
      Thread trackThread = new Thread(partnerTrack, partnerTrack.getPartnerName());
      fLogger.debug("Now starting thread for partner " + partnerTrack.getPartnerName());
      trackThread.start();
      threads.add(trackThread);
    }

    fLogger.info("TestCase was started.");

    // Wait for return or error
    waitForPartnerTracksOrError();
    if (measureTestcoverage) {
      Thread thread =
          new Thread() {

            @Override
            public void run() {
              try {
                sleep(wait_time_for_coverage_markers);
              } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              instance.setAllMarkersReceived(true);
            }
          };
      allMarkersReceived = false;
      thread.start();

      waitForAllCoverageMarkers();
    }

    if (fProblemOccurred || fAbortedByUser) {

      for (PartnerTrack partnerTrack : fPartnerTracks.keySet()) {
        if (partnerTrack.getStatus().isError() || partnerTrack.getStatus().isFailure()) {
          fLogger.info(
              String.format(
                  "A test failure or error occurred on %s: %s",
                  partnerTrack.getName(), partnerTrack.getStatus().getMessage()));
        }
      }

      fLogger.debug("Trying to interrupt all threads...");

      // Interrupt all threads
      for (Thread t : threads) {
        if (t.isAlive()) t.interrupt();
      }

      /*
       * HTTPClient methods are not impressed by interruptions. Deal with
       * them the "hard way": Calling this method effectively closes the
       * I/O connections beneath the HTTP POSTs.
       */
      fConnectionManager.shutdown();

      fLogger.debug("All threads interrupted. Waiting for threads...");

      // Wait till all have really returned
      waitForPartnerTracks();

    } else {
      fLogger.info("Test case passed.");
    }

    fLogger.debug("All threads returned.");

    fServer.stopTest(this);

    fLogger.info("Stopping testCase " + fTestCase.getName());
  }
  @Test
  public void testAsyncRangeRequests()
      throws IOException, URISyntaxException, InterruptedException {
    final URL testResourceUrl = new URL(VAULT_BASE_URI.toURL(), "asyncRangeRequestTestFile.txt");

    final MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager();
    cm.getParams().setDefaultMaxConnectionsPerHost(50);
    final HttpClient client = new HttpClient(cm);

    // prepare 8MiB test data:
    final byte[] plaintextData = new byte[2097152 * Integer.BYTES];
    final ByteBuffer bbIn = ByteBuffer.wrap(plaintextData);
    for (int i = 0; i < 2097152; i++) {
      bbIn.putInt(i);
    }

    // put request:
    final EntityEnclosingMethod putMethod = new PutMethod(testResourceUrl.toString());
    putMethod.setRequestEntity(new ByteArrayRequestEntity(plaintextData));
    final int putResponse = client.executeMethod(putMethod);
    putMethod.releaseConnection();
    Assert.assertEquals(201, putResponse);

    // multiple async range requests:
    final List<ForkJoinTask<?>> tasks = new ArrayList<>();
    final Random generator = new Random(System.currentTimeMillis());

    final AtomicBoolean success = new AtomicBoolean(true);

    // 10 full interrupted requests:
    for (int i = 0; i < 10; i++) {
      final ForkJoinTask<?> task =
          ForkJoinTask.adapt(
              () -> {
                try {
                  final HttpMethod getMethod = new GetMethod(testResourceUrl.toString());
                  final int statusCode = client.executeMethod(getMethod);
                  if (statusCode != 200) {
                    LOG.error("Invalid status code for interrupted full request");
                    success.set(false);
                  }
                  getMethod.getResponseBodyAsStream().read();
                  getMethod.getResponseBodyAsStream().close();
                  getMethod.releaseConnection();
                } catch (IOException e) {
                  throw new RuntimeException(e);
                }
              });
      tasks.add(task);
    }

    // 50 crappy interrupted range requests:
    for (int i = 0; i < 50; i++) {
      final int lower = generator.nextInt(plaintextData.length);
      final ForkJoinTask<?> task =
          ForkJoinTask.adapt(
              () -> {
                try {
                  final HttpMethod getMethod = new GetMethod(testResourceUrl.toString());
                  getMethod.addRequestHeader("Range", "bytes=" + lower + "-");
                  final int statusCode = client.executeMethod(getMethod);
                  if (statusCode != 206) {
                    LOG.error("Invalid status code for interrupted range request");
                    success.set(false);
                  }
                  getMethod.getResponseBodyAsStream().read();
                  getMethod.getResponseBodyAsStream().close();
                  getMethod.releaseConnection();
                } catch (IOException e) {
                  throw new RuntimeException(e);
                }
              });
      tasks.add(task);
    }

    // 50 normal open range requests:
    for (int i = 0; i < 50; i++) {
      final int lower = generator.nextInt(plaintextData.length - 512);
      final int upper = plaintextData.length - 1;
      final ForkJoinTask<?> task =
          ForkJoinTask.adapt(
              () -> {
                try {
                  final HttpMethod getMethod = new GetMethod(testResourceUrl.toString());
                  getMethod.addRequestHeader("Range", "bytes=" + lower + "-");
                  final byte[] expected = Arrays.copyOfRange(plaintextData, lower, upper + 1);
                  final int statusCode = client.executeMethod(getMethod);
                  final byte[] responseBody = new byte[upper - lower + 10];
                  final int bytesRead =
                      IOUtils.read(getMethod.getResponseBodyAsStream(), responseBody);
                  getMethod.releaseConnection();
                  if (statusCode != 206) {
                    LOG.error("Invalid status code for open range request");
                    success.set(false);
                  } else if (upper - lower + 1 != bytesRead) {
                    LOG.error("Invalid response length for open range request");
                    success.set(false);
                  } else if (!Arrays.equals(
                      expected, Arrays.copyOfRange(responseBody, 0, bytesRead))) {
                    LOG.error("Invalid response body for open range request");
                    success.set(false);
                  }
                } catch (IOException e) {
                  throw new RuntimeException(e);
                }
              });
      tasks.add(task);
    }

    // 200 normal closed range requests:
    for (int i = 0; i < 200; i++) {
      final int pos1 = generator.nextInt(plaintextData.length - 512);
      final int pos2 = pos1 + 512;
      final ForkJoinTask<?> task =
          ForkJoinTask.adapt(
              () -> {
                try {
                  final int lower = Math.min(pos1, pos2);
                  final int upper = Math.max(pos1, pos2);
                  final HttpMethod getMethod = new GetMethod(testResourceUrl.toString());
                  getMethod.addRequestHeader("Range", "bytes=" + lower + "-" + upper);
                  final byte[] expected = Arrays.copyOfRange(plaintextData, lower, upper + 1);
                  final int statusCode = client.executeMethod(getMethod);
                  final byte[] responseBody = new byte[upper - lower + 1];
                  final int bytesRead =
                      IOUtils.read(getMethod.getResponseBodyAsStream(), responseBody);
                  getMethod.releaseConnection();
                  if (statusCode != 206) {
                    LOG.error("Invalid status code for closed range request");
                    success.set(false);
                  } else if (upper - lower + 1 != bytesRead) {
                    LOG.error("Invalid response length for closed range request");
                    success.set(false);
                  } else if (!Arrays.equals(
                      expected, Arrays.copyOfRange(responseBody, 0, bytesRead))) {
                    LOG.error("Invalid response body for closed range request");
                    success.set(false);
                  }
                } catch (IOException e) {
                  throw new RuntimeException(e);
                }
              });
      tasks.add(task);
    }

    Collections.shuffle(tasks, generator);

    final ForkJoinPool pool = new ForkJoinPool(4);
    for (ForkJoinTask<?> task : tasks) {
      pool.execute(task);
    }
    for (ForkJoinTask<?> task : tasks) {
      task.join();
    }
    pool.shutdown();
    cm.shutdown();

    Assert.assertTrue(success.get());
  }
Beispiel #6
0
  /**
   * Shutdown the service engine. This performs cleanup before the BPE is terminated. Once this
   * method has been called, init() must be called before the transformation engine can be started
   * again with a call to start().
   *
   * @throws AxisFault if the engine is unable to shut down.
   */
  public void shutDown() throws AxisFault {

    ClassLoader old = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    try {
      if (_poller != null)
        try {
          __log.debug("shutting down poller");
          _poller.stop();
          _poller = null;
        } catch (Throwable t) {
          __log.debug("Error stopping poller.", t);
        }

      if (_bpelServer != null)
        try {
          __log.debug("shutting down ODE server.");
          _bpelServer.shutdown();
          _bpelServer = null;
        } catch (Throwable ex) {
          __log.debug("Error stopping services.", ex);
        }

      if (_cronScheduler != null) {
        try {
          __log.debug("shutting down cron scheduler.");
          _cronScheduler.shutdown();
          _cronScheduler = null;
        } catch (Exception ex) {
          __log.debug("Cron scheduler couldn't be shutdown.", ex);
        }
      }

      if (_scheduler != null)
        try {
          __log.debug("shutting down scheduler.");
          _scheduler.shutdown();
          _scheduler = null;
        } catch (Exception ex) {
          __log.debug("Scheduler couldn't be shutdown.", ex);
        }

      if (_store != null)
        try {
          _store.shutdown();
          _store = null;
        } catch (Throwable t) {
          __log.debug("Store could not be shutdown.", t);
        }

      if (_daoCF != null)
        try {
          _daoCF.shutdown();
        } catch (Throwable ex) {
          __log.debug("DOA shutdown failed.", ex);
        } finally {
          _daoCF = null;
        }

      if (_db != null)
        try {
          _db.shutdown();

        } catch (Throwable ex) {
          __log.debug("DB shutdown failed.", ex);
        } finally {
          _db = null;
        }

      if (_txMgr != null) {
        __log.debug("shutting down transaction manager.");
        _txMgr = null;
      }

      if (_connector != null) {
        try {
          __log.debug("shutdown BpelConnector");
          _connector.shutdown();
          _connector = null;
        } catch (Throwable t) {
          __log.error("Unable to cleanup temp files.", t);
        }
      }
      if (httpConnectionManager != null) {
        __log.debug("shutting down HTTP connection manager.");
        try {
          httpConnectionManager.shutdown();
          httpConnectionManager = null;
        } catch (Throwable t) {
          __log.error("Unable to shut down HTTP connection manager.", t);
        }
      }
      if (idleConnectionTimeoutThread != null) {
        __log.debug("shutting down Idle Connection Timeout Thread.");
        try {
          idleConnectionTimeoutThread.shutdown();
          idleConnectionTimeoutThread = null;
        } catch (Throwable t) {
          __log.error("Unable to shut down Idle Connection Timeout Thread.", t);
        }
      }
      try {
        __log.debug("cleaning up temporary files.");
        TempFileManager.cleanup();
      } catch (Throwable t) {
        __log.error("Unable to cleanup temp files.", t);
      }

      if (_executorService != null) {
        _executorService.shutdownNow();
        _executorService = null;
      }

      __log.info(__msgs.msgOdeShutdownCompleted());
    } finally {
      Thread.currentThread().setContextClassLoader(old);
    }
  }
Beispiel #7
0
 public void shutdown() {
   executor.shutdown();
   manager.shutdown();
   debugTimer.cancel();
 }
 /**
  * Shutdown hook that closes the underlying {@link HttpConnectionManager}'s connection pool, if
  * any.
  */
 public void destroy() {
   HttpConnectionManager connectionManager = getHttpClient().getHttpConnectionManager();
   if (connectionManager instanceof MultiThreadedHttpConnectionManager) {
     ((MultiThreadedHttpConnectionManager) connectionManager).shutdown();
   }
 }