use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.
the class TransactionTest method testDoubleCommit.
@Test(timeout = 10000)
@SuppressWarnings("deprecation")
public void testDoubleCommit() throws TxnFailedException {
String endpoint = "localhost";
String streamName = "testDoubleCommit";
int port = TestUtils.getAvailableListenPort();
String event = "Event\n";
String routingKey = "RoutingKey";
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager("scope", endpoint, port);
streamManager.createScope("scope");
streamManager.createStream("scope", streamName, null);
@Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
EventWriterConfig eventWriterConfig = EventWriterConfig.builder().transactionTimeoutTime(60000).build();
@Cleanup TransactionalEventStreamWriter<String> producer = clientFactory.createTransactionalEventWriter(streamName, new JavaSerializer<>(), eventWriterConfig);
Transaction<String> transaction = producer.beginTxn();
transaction.writeEvent(routingKey, event);
transaction.commit();
AssertExtensions.assertThrows(TxnFailedException.class, () -> transaction.commit());
}
use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.
the class TransactionTest method testDeleteStreamWithOpenTransaction.
@Test(timeout = 30000)
public void testDeleteStreamWithOpenTransaction() throws Exception {
String endpoint = "localhost";
String scopeName = "scope";
String streamName = "abc";
int port = TestUtils.getAvailableListenPort();
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager(scopeName, endpoint, port);
streamManager.createScope(scopeName);
streamManager.createStream(scopeName, streamName, StreamConfiguration.builder().build());
MockClientFactory clientFactory = streamManager.getClientFactory();
@Cleanup final TransactionalEventStreamWriter<String> writer = clientFactory.createTransactionalEventWriter("writerId1", streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
// Transactions 9-10 will be opened.
for (int i = 0; i < 11; i++) {
final Transaction<String> txn = writer.beginTxn();
log.info("i={}, txnId={}", i, txn.getTxnId());
if (i <= 8) {
txn.writeEvent("foo");
}
if (i <= 6) {
txn.flush();
}
if (i <= 4) {
txn.commit();
}
}
boolean sealed = streamManager.sealStream(scopeName, streamName);
Assert.assertTrue(sealed);
boolean deleted = streamManager.deleteStream(scopeName, streamName);
Assert.assertTrue(deleted);
}
use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.
the class AppendTest method appendThroughConditionalClient.
@Test(timeout = 10000)
public void appendThroughConditionalClient() throws Exception {
String endpoint = "localhost";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
String scope = "scope";
String stream = "appendThroughConditionalClient";
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
server.startListening();
@Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
@Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
@Cleanup Controller controller = new MockController(endpoint, port, connectionPool, true);
controller.createScope(scope);
controller.createStream(scope, stream, StreamConfiguration.builder().build());
ConditionalOutputStreamFactoryImpl segmentClient = new ConditionalOutputStreamFactoryImpl(controller, connectionPool);
Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
@Cleanup ConditionalOutputStream out = segmentClient.createConditionalOutputStream(segment, DelegationTokenProviderFactory.createWithEmptyToken(), EventWriterConfig.builder().build());
assertTrue(out.write(ByteBuffer.wrap(testString.getBytes()), 0));
}
use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.
the class AppendTest method miniBenchmark.
@Test(timeout = 20000)
public void miniBenchmark() throws InterruptedException, ExecutionException, TimeoutException {
String endpoint = "localhost";
String streamName = "miniBenchmark";
int port = TestUtils.getAvailableListenPort();
byte[] testPayload = new byte[1000];
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
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<ByteBuffer> producer = clientFactory.createEventWriter(streamName, new ByteBufferSerializer(), EventWriterConfig.builder().build());
long blockingTime = timeWrites(testPayload, 3000, producer, true);
long nonBlockingTime = timeWrites(testPayload, 60000, producer, false);
System.out.println("Blocking took: " + blockingTime + "ms.");
System.out.println("Non blocking took: " + nonBlockingTime + "ms.");
assertTrue(blockingTime < 10000);
assertTrue(nonBlockingTime < 10000);
}
use of io.pravega.segmentstore.contracts.tables.TableStore in project pravega by pravega.
the class AppendTest method appendThroughStreamingClient.
@Test(timeout = 10000)
public void appendThroughStreamingClient() throws InterruptedException, ExecutionException, TimeoutException {
String endpoint = "localhost";
String streamName = "appendThroughStreamingClient";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, SERVICE_BUILDER.getLowPriorityExecutor());
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);
}
Aggregations