use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class SetupUtils method startAllServices.
/**
* Start all pravega related services required for the test deployment.
*
* @param numThreads the number of threads for the internal client threadpool.
* @throws Exception on any errors.
*/
public void startAllServices(Integer numThreads) throws Exception {
if (!this.started.compareAndSet(false, true)) {
log.warn("Services already started, not attempting to start again");
return;
}
this.connectionFactory = new ConnectionFactoryImpl(clientConfig, numThreads);
this.controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(clientConfig).build(), connectionFactory.getInternalExecutor());
this.clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory);
// Start zookeeper.
this.zkTestServer = new TestingServerStarter().start();
this.zkTestServer.start();
// Start Pravega Service.
ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
this.server = new PravegaConnectionListener(false, servicePort, store);
this.server.startListening();
log.info("Started Pravega Service");
// Start Controller.
this.controllerWrapper = new ControllerWrapper(this.zkTestServer.getConnectString(), false, true, controllerRPCPort, "localhost", servicePort, Config.HOST_STORE_CONTAINER_COUNT, controllerRESTPort);
this.controllerWrapper.awaitRunning();
this.controllerWrapper.getController().createScope(scope).get();
log.info("Initialized Pravega Controller");
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class AppendTest method miniBenchmark.
@Test(timeout = 40000)
public void miniBenchmark() throws InterruptedException, ExecutionException, TimeoutException {
String endpoint = "localhost";
String streamName = "abc";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager("Scope", endpoint, port);
@Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
streamManager.createScope("Scope");
streamManager.createStream("Scope", streamName, null);
@Cleanup EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
long blockingTime = timeWrites(testString, 200, producer, true);
long nonBlockingTime = timeWrites(testString, 1000, producer, false);
System.out.println("Blocking took: " + blockingTime + "ms.");
System.out.println("Non blocking took: " + nonBlockingTime + "ms.");
assertTrue(blockingTime < 15000);
assertTrue(nonBlockingTime < 15000);
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class AppendTest method appendThroughStreamingClient.
@Test
public void appendThroughStreamingClient() throws InterruptedException, ExecutionException, TimeoutException {
String endpoint = "localhost";
String streamName = "abc";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager("Scope", endpoint, port);
@Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
streamManager.createScope("Scope");
streamManager.createStream("Scope", streamName, null);
@Cleanup EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
Future<Void> ack = producer.writeEvent(testString);
ack.get(5, TimeUnit.SECONDS);
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class AppendTest method testSetupOnNonExistentSegment.
@Test
public void testSetupOnNonExistentSegment() throws Exception {
String segment = "123";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup EmbeddedChannel channel = createChannel(store);
UUID uuid = UUID.randomUUID();
NoSuchSegment setup = (NoSuchSegment) sendRequest(channel, new SetupAppend(1, uuid, segment, ""));
assertEquals(segment, setup.getSegment());
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class AppendTest method sendReceivingAppend.
@Test
public void sendReceivingAppend() throws Exception {
String segment = "123";
ByteBuf data = Unpooled.wrappedBuffer("Hello world\n".getBytes());
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup EmbeddedChannel channel = createChannel(store);
SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, ""));
assertEquals(segment, created.getSegment());
UUID uuid = UUID.randomUUID();
AppendSetup setup = (AppendSetup) sendRequest(channel, new SetupAppend(2, uuid, segment, ""));
assertEquals(segment, setup.getSegment());
assertEquals(uuid, setup.getWriterId());
DataAppended ack = (DataAppended) sendRequest(channel, new Append(segment, uuid, data.readableBytes(), data, null));
assertEquals(uuid, ack.getWriterId());
assertEquals(data.readableBytes(), ack.getEventNumber());
assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber());
}
Aggregations