Package com.google.common.base

Examples of com.google.common.base.Stopwatch


      SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class),
            createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100);

      HttpCommand command = createHttpCommandForFailureCount(59);

      Stopwatch watch = new Stopwatch().start();
      assertTrue(retry.shouldRetryRequestOnError(command, response, error));
      assertEquals(command.getFailureCount(), 60);
      // allow for slightly inaccurate system timers
      assertTrue(watch.stop().elapsed(TimeUnit.MILLISECONDS) >= 98);
   }
View Full Code Here


      SQSErrorRetryHandler retry = new SQSErrorRetryHandler(createMock(AWSUtils.class),
            createMock(BackoffLimitedRetryHandler.class), ImmutableSet.<String> of(), 60, 100);

      HttpCommand command = createHttpCommandForFailureCount(60);

      Stopwatch watch = new Stopwatch().start();
      assertFalse(retry.shouldRetryRequestOnError(command, response, error));
      assertEquals(command.getFailureCount(), 61);
      assertTrue(watch.stop().elapsed(TimeUnit.MILLISECONDS) < 100);
   }
View Full Code Here

      }
   }

   protected ServiceStats trackAvailabilityOfProcessOnNode(Statement process, String processName, NodeMetadata node) {
      ServiceStats stats = new ServiceStats();
      Stopwatch watch = new Stopwatch().start();
      ExecResponse exec = client.runScriptOnNode(node.getId(), process, runAsRoot(false).wrapInInitScript(false));
      stats.backgroundProcessMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);
      watch.reset().start();
     
      HostAndPort socket = null;
      try {
         socket = openSocketFinder.findOpenSocketOnNode(node, 8080, 60, TimeUnit.SECONDS);
      } catch (NoSuchElementException e) {
         throw new NoSuchElementException(format("%s%n%s%s", e.getMessage(), exec.getOutput(), exec.getError()));
      }

      stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);

      getAnonymousLogger().info(format("<< %s on node(%s)[%s] %s", processName, node.getId(), socket, stats));
      return stats;
   }
View Full Code Here

   protected void createAndRunAServiceInGroup(String group) throws RunNodesException {
      // note that some cloud providers do not support mixed case tag names
      ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("test", group);
     
      ImmutableSet<String> tags = ImmutableSet. of(group);
      Stopwatch watch = new Stopwatch().start();
      NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1,
            inboundPorts(22, 8080).blockOnPort(22, 300).userMetadata(userMetadata).tags(tags)));
      long createSeconds = watch.elapsedTime(TimeUnit.SECONDS);

      final String nodeId = node.getId();

      checkUserMetadataContains(node, userMetadata);
      checkTagsInNodeEquals(node, tags);

      getAnonymousLogger().info(
            format("<< available node(%s) os(%s) in %ss", node.getId(), node.getOperatingSystem(), createSeconds));

      watch.reset().start();

      client.runScriptOnNode(nodeId, JettyStatements.install(), nameTask("configure-jetty"));

      long configureSeconds = watch.elapsedTime(TimeUnit.SECONDS);

      getAnonymousLogger().info(
            format(
                  "<< configured node(%s) with %s and jetty %s in %ss",
                  nodeId,
View Full Code Here

    isFull = false;
  }

  @Override
  public void endSlice() {
    Stopwatch stopwatch = Stopwatch.createStarted();
    sortData();
    log.info(
        "Sorted " + valuesHeld + " items in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms");
    stopwatch.reset().start();
    writeOutData();
    log.info("Wrote " + getStoredSize() + " bytes of data in "
        + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms");
  }
View Full Code Here

      }
   }

   protected ServiceStats trackAvailabilityOfProcessOnNode(Statement process, String processName, NodeMetadata node) {
      ServiceStats stats = new ServiceStats();
      Stopwatch watch = new Stopwatch().start();
      ExecResponse exec = client.runScriptOnNode(node.getId(), process, runAsRoot(false).wrapInInitScript(false));
      stats.backgroundProcessMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);
      watch.reset().start();
     
      HostAndPort socket = null;
      try {
         socket = openSocketFinder.findOpenSocketOnNode(node, 8080, 600, TimeUnit.SECONDS);
      } catch (NoSuchElementException e) {
         throw new NoSuchElementException(format("%s%n%s%s", e.getMessage(), exec.getOutput(), exec.getError()));
      }

      stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);

      getAnonymousLogger().info(format("<< %s on node(%s)[%s] %s", processName, node.getId(), socket, stats));
      return stats;
   }
View Full Code Here

   protected void createAndRunAServiceInGroup(String group) throws RunNodesException {
      // note that some cloud providers do not support mixed case tag names
      ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("test", group);
     
      ImmutableSet<String> tags = ImmutableSet. of(group);
      Stopwatch watch = new Stopwatch().start();
      NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1,
            inboundPorts(22, 8080).blockOnPort(22, 300).userMetadata(userMetadata).tags(tags)));
      long createSeconds = watch.elapsedTime(TimeUnit.SECONDS);

      final String nodeId = node.getId();

      checkUserMetadataContains(node, userMetadata);
      checkTagsInNodeEquals(node, tags);

      getAnonymousLogger().info(
            format("<< available node(%s) os(%s) in %ss", node.getId(), node.getOperatingSystem(), createSeconds));

      watch.reset().start();

      client.runScriptOnNode(nodeId, JettyStatements.install(), nameTask("configure-jetty"));

      long configureSeconds = watch.elapsedTime(TimeUnit.SECONDS);

      getAnonymousLogger().info(
            format(
                  "<< configured node(%s) with %s and jetty %s in %ss",
                  nodeId,
View Full Code Here

*/
public class StopwatchBenchmark {
  @Benchmark long stopwatch(int reps) {
    long total = 0;
    for (int i = 0; i < reps; i++) {
      Stopwatch s = Stopwatch.createStarted();
      // here is where you would do something
      total += s.elapsed(TimeUnit.NANOSECONDS);
    }
    return total;
  }
View Full Code Here

            trySetConnectionProperties(query, connection);
            long start = System.nanoTime();

            try (Statement statement = connection.createStatement()) {
                TimeLimiter limiter = new SimpleTimeLimiter();
                Stopwatch stopwatch = Stopwatch.createStarted();
                Statement limitedStatement = limiter.newProxy(statement, Statement.class, timeout.toMillis(), TimeUnit.MILLISECONDS);
                try (final ResultSet resultSet = limitedStatement.executeQuery(query.getQuery())) {
                    List<List<Object>> results = limiter.callWithTimeout(getResultSetConverter(resultSet), timeout.toMillis() - stopwatch.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, true);
                    return new QueryResult(State.SUCCESS, null, nanosSince(start), results);
                }
                catch (AssertionError e) {
                    if (e.getMessage().startsWith("unimplemented type:")) {
                        return new QueryResult(State.INVALID, null, null, ImmutableList.<List<Object>>of());
View Full Code Here

        return execute(PartitionContextBuilder.empty(), retry, callback);
    }

    @Override
    public <R> R execute(PartitionContext partitionContext, RetryPolicy retry, ServiceCallback<S, R> callback) {
        Stopwatch sw = new Stopwatch(_ticker).start();
        int numAttempts = 0;
        Exception lastException = null;

        do {
            Iterable<ServiceEndPoint> allEndPoints = getAllEndPoints();
            if (Iterables.isEmpty(allEndPoints)) {
                throw (lastException == null)
                        ? new NoAvailableHostsException()
                        : new NoAvailableHostsException(lastException);
            }

            Iterable<ServiceEndPoint> validEndPoints = getValidEndPoints(allEndPoints);
            if (Iterables.isEmpty(validEndPoints)) {
                throw (lastException == null)
                        ? new OnlyBadHostsException()
                        : new OnlyBadHostsException(lastException);
            }

            ServiceEndPoint endPoint = chooseEndPoint(validEndPoints, partitionContext);
            if (endPoint == null) {
                throw (lastException == null)
                        ? new NoSuitableHostsException()
                        : new NoSuitableHostsException(lastException);
            }

            try {
                R result = executeOnEndPoint(endPoint, callback);
                _numExecuteSuccesses.mark();
                return result;
            } catch (Exception e) {
                _numExecuteAttemptFailures.mark();

                // Don't retry if exception is too severe.
                if (!isRetriableException(e)) {
                    throw Throwables.propagate(e);
                }

                LOG.info("Retriable exception from end point id: {}, {}", endPoint.getId(), e.toString());
                LOG.debug("Exception", e);
                lastException = e;
            }
        } while (retry.allowRetry(++numAttempts, sw.elapsedMillis()));

        throw new MaxRetriesException(lastException);
    }
View Full Code Here

TOP

Related Classes of com.google.common.base.Stopwatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.