Search in sources :

Example 66 with TableStore

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());
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) Test(org.junit.Test)

Example 67 with TableStore

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);
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) Test(org.junit.Test)

Example 68 with TableStore

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));
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) ConditionalOutputStream(io.pravega.client.segment.impl.ConditionalOutputStream) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) Segment(io.pravega.client.segment.impl.Segment) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) ConditionalOutputStreamFactoryImpl(io.pravega.client.segment.impl.ConditionalOutputStreamFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Test(org.junit.Test)

Example 69 with TableStore

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);
}
Also used : ByteBufferSerializer(io.pravega.client.stream.impl.ByteBufferSerializer) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) ByteBuffer(java.nio.ByteBuffer) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Test(org.junit.Test)

Example 70 with TableStore

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);
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) Test(org.junit.Test)

Aggregations

TableStore (io.pravega.segmentstore.contracts.tables.TableStore)81 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)69 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)54 Cleanup (lombok.Cleanup)49 Test (org.junit.Test)48 TestingServerStarter (io.pravega.test.common.TestingServerStarter)29 lombok.val (lombok.val)28 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)26 Before (org.junit.Before)26 ControllerWrapper (io.pravega.test.integration.demo.ControllerWrapper)23 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)20 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)18 CompletableFuture (java.util.concurrent.CompletableFuture)18 PassingTokenVerifier (io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier)14 TableEntry (io.pravega.segmentstore.contracts.tables.TableEntry)13 InMemoryTableStore (io.pravega.segmentstore.storage.mocks.InMemoryTableStore)12 WireCommands (io.pravega.shared.protocol.netty.WireCommands)12 Random (java.util.Random)12 CompletionException (java.util.concurrent.CompletionException)12 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)11