Package com.netflix.astyanax.connectionpool.LatencyScoreStrategy

Examples of com.netflix.astyanax.connectionpool.LatencyScoreStrategy.Instance


       
        final AtomicBoolean timeoutsEnabled = new AtomicBoolean(false);
        final AtomicLong lastOperationCount = new AtomicLong();
       
        EmaLatencyScoreStrategyImpl latency = new EmaLatencyScoreStrategyImpl(1000, 0, 10);
        final Instance sampler = latency.createInstance();
        latency.start(new Listener() {
            @Override
            public void onUpdate() {
            }
            @Override
            public void onReset() {
            }
        });
        final Function<TestDriver, Void> function = new ProbabalisticFunction.Builder<TestDriver, Void>()
            .withDefault(new Function<TestDriver, Void>() {
                public Void apply(TestDriver arg0) {
                    return null;
                }
            })
            .withAlways(new Runnable() {
                public void run() {
                    think(10, 30);
                }
            })
//            .withProbability(0.0001, new Function<TestDriver, Void>() {
//                public Void apply(@Nullable TestDriver arg0) {
//                    if (timeoutsEnabled.get()) {
//                        think(1100, 0);
//                        throw new RuntimeException(new TimeoutException("TimeoutException"));
//                    }
//                    return null;
//                }
//            })
//            .withProbability(0.0001, new Function<TestDriver, Void>() {
//                public Void apply(@Nullable TestDriver arg0) {
//                    throw new RuntimeException(new UnknownException(new Exception("UnknownExceptionDescription")));
//                }
//            })
//            .withProbability(0.0001, new Function<TestDriver, Void>() {
//                public Void apply(@Nullable TestDriver arg0) {
//                    think(1000, 0);
//                    throw new RuntimeException(new OperationTimeoutException("OperationTimeoutException"));
//                }
//            })
//            .withProbability(0.0001, new Function<TestDriver, Void>() {
//                public Void apply(@Nullable TestDriver arg0) {
//                    throw new RuntimeException(new HostDownException("HostDownException"));
//                }
//            })
//            .withProbability(0.01, new Function<TestDriver, Void>() {
//                public Void apply(@Nullable TestDriver arg0) {
//                    throw new RuntimeException(new ConnectionAbortedException("ConnectionAbortedException"));
//                }
//            })
//            .withProbability(0.0001, new Function<TestDriver, Void>() {
//                public Void apply(@Nullable TestDriver arg0) {
//                    throw new RuntimeException(new BadRequestException("BadRequestException"));
//                }
//            })
//            .withProbability(0.0001, new Function<TestDriver, Void>() {
//                public Void apply(@Nullable TestDriver arg0) {
//                    throw new RuntimeException(new TokenRangeOfflineException("TokenRangeOfflineException"));
//                }
//            })
//            .withProbability(0.0001, new Function<TestDriver, Void>() {
//                public Void apply(@Nullable TestDriver arg0) {
//                    throw new RuntimeException(new TransportException("TransportException"));
//                }
//            })
        .build();
       
        final List<HostConnectionPool<TestClient>> hostPools = Lists.newArrayList(pool.getActivePools());
       
        final TestDriver driver = new TestDriver.Builder()
            .withIterationCount(0)
            .withThreadCount(200)
//            .withFutures(100,  TimeUnit.MILLISECONDS)
            .withCallsPerSecondSupplier(Suppliers.ofInstance(200))
//            .withFutures(100, TimeUnit.MILLISECONDS)
            .withCallback(new Function<TestDriver, Void>() {
                public Void apply(final TestDriver driver) {
                    long startTime = System.nanoTime();
                    try {
                        pool.executeWithFailover(new TestOperation() {
                            public String execute(TestClient client) throws ConnectionException, OperationException {
                                try {
                                    function.apply(driver);
                                    return null;
                                }
                                catch (RuntimeException e) {
                                    if (e.getCause() instanceof ConnectionException)
                                        throw (ConnectionException)e.getCause();
                                    throw e;
                                }
                            }
                        }, new RunOnce());
                    } catch (PoolTimeoutException e) {
                        LOG.info(e.getMessage());
                    } catch (ConnectionException e) {
                    } finally {
                        sampler.addSample((System.nanoTime() - startTime)/1000000);
                    }
                   
                    return null;
                }
            })
           
            //
            //  Event to turn timeouts on/off
            //
            .withRecurringEvent(10,  TimeUnit.SECONDS,  new Function<TestDriver, Void>() {
                @Override
                public Void apply(TestDriver driver) {
                    timeoutsEnabled.getAndSet(!timeoutsEnabled.get());
//                    LOG.info("Toggle timeouts " + timeoutsEnabled.get());
                    return null;
                }
            })
           
            //
            //  Print status information
            //
            .withRecurringEvent(1,  TimeUnit.SECONDS,  new Function<TestDriver, Void>() {
                @Override
                public Void apply(TestDriver driver) {
                    long opCount = lastOperationCount.get();
                    lastOperationCount.set(driver.getOperationCount());
                   
                    System.out.println("" + driver.getRuntime() + "," + sampler.getScore() + "," + (lastOperationCount.get() - opCount));
                    System.out.println(monitor.toString());
                    System.out.println(monitor.toString());
                    for (HostConnectionPool<TestClient> host : pool.getPools()) {
                        System.out.println("   " + host.toString());
                    }
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.connectionpool.LatencyScoreStrategy.Instance

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.