public MovingAverageRateFactory(Timer timer) { this.avgs = new CopyOnWriteArrayList<SampledMovingAverageRate>(); this.timer = timer; Function0<BoxedUnit> sampleTask = new Function0<BoxedUnit>() { public BoxedUnit apply() { sampleAll(); return null; } }; this.timerTask = timer.schedulePeriodically( Time.now(), Duration.fromSeconds(DEFAULT_INTERVAL_SECS), sampleTask); }
public static <T> T validateFutureSucceededAndGetResult(Future<T> future) throws Exception { try { return Await.result(future, Duration.fromSeconds(10)); } catch (Exception ex) { fail("unexpected exception " + ex.getClass().getName()); throw ex; } } }
.handshakeWithClientInfo(handshakeWithClientInfo) .clientBuilder(ClientBuilder.get() .connectTimeout(Duration.fromSeconds(1)) .tcpConnectTimeout(Duration.fromSeconds(1)) .requestTimeout(Duration.fromSeconds(2)) .hostConnectionLimit(2) .hostConnectionCoresize(2)
static DistributedLogClientBuilder createDistributedLogClientBuilder(ServerSet serverSet) { return DistributedLogClientBuilder.newBuilder() .name("rebalancer_tool") .clientId(ClientId$.MODULE$.apply("rebalancer_tool")) .maxRedirects(2) .serverSet(serverSet) .clientBuilder(ClientBuilder.get() .connectionTimeout(Duration.fromSeconds(2)) .tcpConnectTimeout(Duration.fromSeconds(2)) .requestTimeout(Duration.fromSeconds(10)) .hostConnectionLimit(1) .hostConnectionCoresize(1) .keepAlive(true) .failFast(false)); }
private ClientBuilder getDefaultClientBuilder() { return ClientBuilder.get() .hostConnectionLimit(1) .tcpConnectTimeout(Duration.fromMilliseconds(200)) .connectTimeout(Duration.fromMilliseconds(200)) .requestTimeout(Duration.fromSeconds(1)); }
@Override protected int runCmd(CommandLine commandLine) throws Exception { try { parseCommandLine(commandLine); } catch (ParseException pe) { System.err.println("ERROR: failed to parse commandline : '" + pe.getMessage() + "'"); printUsage(); return -1; } DistributedLogClientBuilder clientBuilder = DistributedLogClientBuilder.newBuilder() .name("proxy_tool") .clientId(ClientId$.MODULE$.apply("proxy_tool")) .maxRedirects(2) .host(address) .clientBuilder(ClientBuilder.get() .connectionTimeout(Duration.fromSeconds(2)) .tcpConnectTimeout(Duration.fromSeconds(2)) .requestTimeout(Duration.fromSeconds(10)) .hostConnectionLimit(1) .hostConnectionCoresize(1) .keepAlive(true) .failFast(false)); Pair<DistributedLogClient, MonitorServiceClient> clientPair = ClientUtils.buildClient(clientBuilder); try { return runCmd(clientPair); } finally { clientPair.getLeft().close(); } }
.serverSet(serverSet.getServerSet()) .clientBuilder(ClientBuilder.get() .connectionTimeout(Duration.fromSeconds(2)) .tcpConnectTimeout(Duration.fromSeconds(2)) .requestTimeout(Duration.fromSeconds(10)) .hostConnectionLimit(1) .hostConnectionCoresize(1)
private void checkAllSubmittedButFailed(BKAsyncLogWriter writer, int batchSize, int recSize, long txIndex) throws Exception { List<LogRecord> records = DLMTestUtil.getLogRecordInstanceList(txIndex, batchSize, recSize); Future<List<Future<DLSN>>> futureResults = writer.writeBulk(records); assertNotNull(futureResults); List<Future<DLSN>> results = Await.result(futureResults, Duration.fromSeconds(10)); assertNotNull(results); assertEquals(results.size(), records.size()); for (Future<DLSN> result : results) { validateFutureFailed(result, IOException.class); } } }
@Test(timeout = 60000) public void testBuildClientsFromSameBuilder() throws Exception { DistributedLogClientBuilder builder = DistributedLogClientBuilder.newBuilder() .name("build-clients-from-same-builder") .clientId(ClientId$.MODULE$.apply("test-builder")) .finagleNameStr("inet!127.0.0.1:7001") .streamNameRegex(".*") .handshakeWithClientInfo(true) .clientBuilder(ClientBuilder.get() .hostConnectionLimit(1) .connectTimeout(Duration.fromSeconds(1)) .tcpConnectTimeout(Duration.fromSeconds(1)) .requestTimeout(Duration.fromSeconds(10))); DistributedLogClient client1 = builder.build(); DistributedLogClient client2 = builder.build(); assertFalse(client1 == client2); } }
@Test(timeout = 60000) public void testGetLogRecordCountAsync() throws Exception { DistributedLogManager dlm = createNewDLM(conf, testNames.getMethodName()); BKAsyncLogWriter writer = (BKAsyncLogWriter) dlm.startAsyncLogSegmentNonPartitioned(); DLMTestUtil.generateCompletedLogSegments(dlm, conf, 2, 10); Future<Long> futureCount = dlm.getLogRecordCountAsync(DLSN.InitialDLSN); Long count = Await.result(futureCount, Duration.fromSeconds(2)); assertEquals(20, count.longValue()); writer.close(); dlm.close(); }
private DLSN checkAllSucceeded(BKAsyncLogWriter writer, int batchSize, int recSize, long ledgerIndex, long entryIndex, long slotIndex, long txIndex) throws Exception { List<LogRecord> records = DLMTestUtil.getLogRecordInstanceList(txIndex, batchSize, recSize); Future<List<Future<DLSN>>> futureResults = writer.writeBulk(records); assertNotNull(futureResults); List<Future<DLSN>> results = Await.result(futureResults, Duration.fromSeconds(10)); assertNotNull(results); assertEquals(results.size(), records.size()); long prevEntryId = 0; DLSN lastDlsn = null; for (Future<DLSN> result : results) { DLSN dlsn = Await.result(result, Duration.fromSeconds(10)); lastDlsn = dlsn; // If we cross a transmission boundary, slot id gets reset. if (dlsn.getEntryId() > prevEntryId) { slotIndex = 0; } assertEquals(ledgerIndex, dlsn.getLogSegmentSequenceNo()); assertEquals(slotIndex, dlsn.getSlotId()); slotIndex++; prevEntryId = dlsn.getEntryId(); } return lastDlsn; }
@Test(timeout = 60000) public void testWriteFutureDoesNotCompleteUntilWritePersisted() throws Exception { String name = testNames.getMethodName(); DistributedLogConfiguration conf = new DistributedLogConfiguration(); conf.setPeriodicFlushFrequencyMilliSeconds(Integer.MAX_VALUE); conf.setImmediateFlushEnabled(false); DistributedLogManager dlmwriter = createNewDLM(conf, name); DistributedLogManager dlmreader = createNewDLM(conf, name); byte[] byteStream = DLMTestUtil.repeatString("abc", 51).getBytes(); // Can't reliably test the future is not completed until fsync is called, since writer.force may just // happen very quickly. But we can test that the mechanics of the future write and api are basically // correct. AppendOnlyStreamWriter writer = dlmwriter.getAppendOnlyStreamWriter(); Future<DLSN> dlsnFuture = writer.write(DLMTestUtil.repeatString("abc", 11).getBytes()); // The real problem is the fsync completes before writes are submitted, so it never takes effect. Thread.sleep(1000); assertFalse(dlsnFuture.isDefined()); writer.force(false); // Must not throw. Await.result(dlsnFuture, Duration.fromSeconds(5)); writer.close(); dlmwriter.close(); AppendOnlyStreamReader reader = dlmreader.getAppendOnlyStreamReader(); byte[] bytesIn = new byte[byteStream.length]; int read = reader.read(bytesIn, 0, 31); assertEquals(31, read); reader.close(); dlmreader.close(); }
@Test(timeout = 60000) public void testAsyncWritePendingWritesAbortedWhenLedgerRollTriggerFails() throws Exception { String name = runtime.getMethodName(); DistributedLogConfiguration confLocal = new DistributedLogConfiguration(); confLocal.loadConf(testConf); confLocal.setOutputBufferSize(1024); confLocal.setMaxLogSegmentBytes(1024); confLocal.setLogSegmentRollingIntervalMinutes(0); DistributedLogManager dlm = createNewDLM(confLocal, name); BKAsyncLogWriter writer = (BKAsyncLogWriter)(dlm.startAsyncLogSegmentNonPartitioned()); // Write one record larger than max seg size. Ledger doesn't roll until next write. int txid = 1; LogRecord record = DLMTestUtil.getLogRecordInstance(txid++, 2048); Future<DLSN> result = writer.write(record); DLSN dlsn = Await.result(result, Duration.fromSeconds(10)); assertEquals(1, dlsn.getLogSegmentSequenceNo()); record = DLMTestUtil.getLogRecordInstance(txid++, MAX_LOGRECORD_SIZE + 1); result = writer.write(record); validateFutureFailed(result, LogRecordTooLongException.class); record = DLMTestUtil.getLogRecordInstance(txid++, MAX_LOGRECORD_SIZE + 1); result = writer.write(record); validateFutureFailed(result, WriteException.class); record = DLMTestUtil.getLogRecordInstance(txid++, MAX_LOGRECORD_SIZE + 1); result = writer.write(record); validateFutureFailed(result, WriteException.class); writer.closeAndComplete(); dlm.close(); }
private void refreshEndpointsWithError() throws Exception { Future<List<ScrayTServiceEndpoint>> eplist = connection .getCombinedClient().getServiceEndpoints(); endpointCache = Await.result(eplist, Duration.fromSeconds(TIMEOUT)); log.debug("Refreshed scray service endpoints: " + Joiner.on(", ").join(endpointCache)); }
public ScrayUUID query(ScrayTQuery query, int queryTimeout) throws SQLException { try { Future<ScrayUUID> fuuid = getClient().query(query); return Await .result(fuuid, Duration.fromSeconds(queryTimeout)); } catch (Exception e) { throw new SQLException(e); } }
public ScrayTResultFrame getResults(ScrayUUID queryId, int queryTimeout) throws SQLException { try { Future<ScrayTResultFrame> fframe = getClient().getResults(queryId); // getResults(queryId); ScrayTResultFrame frame = Await.result(fframe, Duration.fromSeconds(queryTimeout)); return frame; } catch (Exception e) { throw new SQLException(e); } } }
public ScrayUUID query(ScrayTQuery query, int queryTimeout) throws SQLException { try { Future<ScrayUUID> fuuid = getClient().query(query); return Await.result(fuuid, Duration.fromSeconds(queryTimeout)); } catch (Exception e) { throw new SQLException(e); } }
public ScrayTResultFrame getResults(ScrayUUID queryId, int queryTimeout) throws SQLException { try { Future<ScrayTResultFrame> fframe = getClient().getResults(queryId, pageIndex); ScrayTResultFrame frame = Await.result(fframe, Duration.fromSeconds(queryTimeout)); pageIndex += 1; return frame; } catch (Exception e) { throw new SQLException(e); } } }
private ClientBuilder getDefaultClientBuilder() { return ClientBuilder.get() .hostConnectionLimit(1) .tcpConnectTimeout(Duration.fromMilliseconds(200)) .connectTimeout(Duration.fromMilliseconds(200)) .requestTimeout(Duration.fromSeconds(1)); }
private ClientBuilder getDefaultClientBuilder(ClientConfig clientConfig) { ClientBuilder builder = ClientBuilder.get() .tcpConnectTimeout(Duration.fromMilliseconds(200)) .connectTimeout(Duration.fromMilliseconds(200)) .requestTimeout(Duration.fromSeconds(1)); if (!clientConfig.getThriftMux()) { builder = builder.hostConnectionLimit(1); } return builder; }