use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestDistributedLogService method testCloseStreamsShouldAbort.
@Test(timeout = 60000)
public void testCloseStreamsShouldAbort() throws Exception {
DistributedLogConfiguration confLocal = newLocalConf();
confLocal.setOutputBufferSize(Integer.MAX_VALUE).setImmediateFlushEnabled(false).setPeriodicFlushFrequencyMilliSeconds(0);
String streamNamePrefix = testName.getMethodName();
DistributedLogServiceImpl localService = createService(serverConf, confLocal);
StreamManagerImpl streamManager = (StreamManagerImpl) localService.getStreamManager();
int numStreams = 10;
int numWrites = 10;
List<Future<WriteResponse>> futureList = Lists.newArrayListWithExpectedSize(numStreams * numWrites);
for (int i = 0; i < numStreams; i++) {
String streamName = streamNamePrefix + "-" + i;
HeartbeatOptions hbOptions = new HeartbeatOptions();
hbOptions.setSendHeartBeatToReader(true);
// make sure the first log segment of each stream created
FutureUtils.result(localService.heartbeatWithOptions(streamName, new WriteContext(), hbOptions));
for (int j = 0; j < numWrites; j++) {
futureList.add(localService.write(streamName, createRecord(i * numWrites + j)));
}
}
assertEquals("There should be " + numStreams + " streams in cache", numStreams, streamManager.getCachedStreams().size());
while (streamManager.getAcquiredStreams().size() < numStreams) {
TimeUnit.MILLISECONDS.sleep(20);
}
for (Stream s : streamManager.getAcquiredStreams().values()) {
StreamImpl stream = (StreamImpl) s;
stream.setStatus(StreamStatus.FAILED);
}
Future<List<Void>> closeResult = localService.closeStreams();
List<Void> closedStreams = Await.result(closeResult);
assertEquals("There should be " + numStreams + " streams closed", numStreams, closedStreams.size());
// all writes should be flushed
for (Future<WriteResponse> future : futureList) {
WriteResponse response = Await.result(future);
assertTrue("Op should fail with " + StatusCode.BK_TRANSMIT_ERROR + " or be rejected : " + response.getHeader().getCode(), StatusCode.BK_TRANSMIT_ERROR == response.getHeader().getCode() || StatusCode.WRITE_EXCEPTION == response.getHeader().getCode() || StatusCode.WRITE_CANCELLED_EXCEPTION == response.getHeader().getCode());
}
// acquired streams should all been removed after we close them
assertTrue("There should be no streams in the acquired cache", streamManager.getAcquiredStreams().isEmpty());
localService.shutdown();
// cached streams wouldn't be removed immediately after streams are closed
// but they should be removed after we shutdown the service
assertTrue("There should be no streams in the cache after shutting down the service", streamManager.getCachedStreams().isEmpty());
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestServiceRequestLimiter method testDynamicLimiter.
@Test(timeout = 60000)
public void testDynamicLimiter() throws Exception {
final AtomicInteger id = new AtomicInteger(0);
final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(dynConf, NullStatsLogger.INSTANCE, new SettableFeature("", 0)) {
@Override
public RequestLimiter<MockRequest> build() {
id.getAndIncrement();
return new MockRequestLimiter();
}
};
limiter.initialize();
assertEquals(1, id.get());
dynConf.setProperty("test1", 1);
assertEquals(2, id.get());
dynConf.setProperty("test2", 2);
assertEquals(3, id.get());
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestServiceRequestLimiter method testDynamicLimiterWithException.
@Test(timeout = 60000)
public void testDynamicLimiterWithException() throws Exception {
final AtomicInteger id = new AtomicInteger(0);
final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(dynConf, NullStatsLogger.INSTANCE, new SettableFeature("", 0)) {
@Override
public RequestLimiter<MockRequest> build() {
if (id.incrementAndGet() >= 2) {
throw new RuntimeException("exception in dynamic limiter build()");
}
return new MockRequestLimiter();
}
};
limiter.initialize();
assertEquals(1, id.get());
try {
dynConf.setProperty("test1", 1);
fail("should have thrown on config failure");
} catch (RuntimeException ex) {
}
assertEquals(2, id.get());
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestZKLogSegmentMetadataStore method setup.
@Before
public void setup() throws Exception {
zkc = TestZooKeeperClientBuilder.newBuilder().uri(createDLMURI("/")).sessionTimeoutMs(zkSessionTimeoutMs).build();
scheduler = OrderedScheduler.newBuilder().name("test-zk-logsegment-metadata-store").corePoolSize(1).build();
DistributedLogConfiguration conf = new DistributedLogConfiguration();
conf.addConfiguration(baseConf);
this.uri = createDLMURI("/" + runtime.getMethodName());
lsmStore = new ZKLogSegmentMetadataStore(conf, zkc, scheduler);
zkc.get().create("/" + runtime.getMethodName(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
this.rootZkPath = "/" + runtime.getMethodName();
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestZKAccessControlManager method setup.
@Before
public void setup() throws Exception {
executorService = Executors.newSingleThreadScheduledExecutor();
zkc = TestZooKeeperClientBuilder.newBuilder().uri(createURI("/")).build();
conf = new DistributedLogConfiguration();
}
Aggregations