Search in sources :

Example 11 with QueueClientFactory

use of co.cask.cdap.data2.queue.QueueClientFactory in project cdap by caskdata.

the class LevelDBQueueTest method forceEviction.

@Override
protected void forceEviction(QueueName queueName, int numGroups) throws Exception {
    QueueEvictor evictor = ((LevelDBQueueClientFactory) queueClientFactory).createEvictor(queueName, numGroups);
    Transaction tx = txSystemClient.startShort();
    // There is no change, just to get the latest transaction for eviction
    txSystemClient.commit(tx);
    Uninterruptibles.getUninterruptibly(evictor.evict(tx));
}
Also used : Transaction(org.apache.tephra.Transaction) QueueEvictor(co.cask.cdap.data2.transaction.queue.QueueEvictor)

Example 12 with QueueClientFactory

use of co.cask.cdap.data2.queue.QueueClientFactory in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method enqueue.

// TODO: Duplicate from AppFabricHttpHandlerTest, remove the AppFabricHttpHandlerTest method after deprecating v2 APIs
private void enqueue(QueueName queueName, final QueueEntry queueEntry) throws Exception {
    QueueClientFactory queueClientFactory = AppFabricTestBase.getInjector().getInstance(QueueClientFactory.class);
    final QueueProducer producer = queueClientFactory.createProducer(queueName);
    // doing inside tx
    TransactionExecutorFactory txExecutorFactory = AppFabricTestBase.getInjector().getInstance(TransactionExecutorFactory.class);
    txExecutorFactory.createExecutor(ImmutableList.of((TransactionAware) producer)).execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            // write more than one so that we can dequeue multiple times for multiple checks
            // we only dequeue twice, but ensure that the drop queues call drops the rest of the entries as well
            int numEntries = 0;
            while (numEntries++ < 5) {
                producer.enqueue(queueEntry);
            }
        }
    });
}
Also used : QueueProducer(co.cask.cdap.data2.queue.QueueProducer) QueueClientFactory(co.cask.cdap.data2.queue.QueueClientFactory) TransactionExecutor(org.apache.tephra.TransactionExecutor) IOException(java.io.IOException) NotFoundException(co.cask.cdap.common.NotFoundException) TransactionExecutorFactory(org.apache.tephra.TransactionExecutorFactory)

Example 13 with QueueClientFactory

use of co.cask.cdap.data2.queue.QueueClientFactory in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method dequeueOne.

private boolean dequeueOne(QueueName queueName) throws Exception {
    QueueClientFactory queueClientFactory = AppFabricTestBase.getInjector().getInstance(QueueClientFactory.class);
    final QueueConsumer consumer = queueClientFactory.createConsumer(queueName, new ConsumerConfig(1L, 0, 1, DequeueStrategy.ROUND_ROBIN, null), 1);
    // doing inside tx
    TransactionExecutorFactory txExecutorFactory = AppFabricTestBase.getInjector().getInstance(TransactionExecutorFactory.class);
    return txExecutorFactory.createExecutor(ImmutableList.of((TransactionAware) consumer)).execute(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return !consumer.dequeue(1).isEmpty();
        }
    });
}
Also used : QueueConsumer(co.cask.cdap.data2.queue.QueueConsumer) QueueClientFactory(co.cask.cdap.data2.queue.QueueClientFactory) ConsumerConfig(co.cask.cdap.data2.queue.ConsumerConfig) IOException(java.io.IOException) NotFoundException(co.cask.cdap.common.NotFoundException) TransactionExecutorFactory(org.apache.tephra.TransactionExecutorFactory)

Example 14 with QueueClientFactory

use of co.cask.cdap.data2.queue.QueueClientFactory in project cdap by caskdata.

the class LevelDBStreamConsumerTest method init.

@BeforeClass
public static void init() throws Exception {
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, tmpFolder.newFolder().getAbsolutePath());
    Injector injector = Guice.createInjector(new ConfigModule(cConf), new NonCustomLocationUnitTestModule().getModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new DataSetsModules().getInMemoryModules(), new DataFabricLevelDBModule(), new TransactionMetricsModule(), new DiscoveryRuntimeModule().getInMemoryModules(), new ExploreClientModule(), new ViewAdminModules().getInMemoryModules(), new NamespaceClientRuntimeModule().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), Modules.override(new StreamAdminModules().getStandaloneModules()).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(StreamMetaStore.class).to(InMemoryStreamMetaStore.class);
            bind(NotificationFeedManager.class).to(NoOpNotificationFeedManager.class);
            bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
        }
    }));
    consumerFactory = injector.getInstance(StreamConsumerFactory.class);
    streamAdmin = injector.getInstance(StreamAdmin.class);
    txClient = injector.getInstance(TransactionSystemClient.class);
    txManager = injector.getInstance(TransactionManager.class);
    queueClientFactory = injector.getInstance(QueueClientFactory.class);
    fileWriterFactory = injector.getInstance(StreamFileWriterFactory.class);
    streamCoordinatorClient = injector.getInstance(StreamCoordinatorClient.class);
    streamCoordinatorClient.startAndWait();
    txManager.startAndWait();
    setupNamespaces(injector.getInstance(NamespacedLocationFactory.class));
}
Also used : NamespaceClientRuntimeModule(co.cask.cdap.common.namespace.guice.NamespaceClientRuntimeModule) ConfigModule(co.cask.cdap.common.guice.ConfigModule) UGIProvider(co.cask.cdap.security.impersonation.UGIProvider) UnsupportedUGIProvider(co.cask.cdap.security.impersonation.UnsupportedUGIProvider) NamespacedLocationFactory(co.cask.cdap.common.namespace.NamespacedLocationFactory) StreamConsumerFactory(co.cask.cdap.data2.transaction.stream.StreamConsumerFactory) DataFabricLevelDBModule(co.cask.cdap.data.runtime.DataFabricLevelDBModule) TransactionMetricsModule(co.cask.cdap.data.runtime.TransactionMetricsModule) ViewAdminModules(co.cask.cdap.data.view.ViewAdminModules) TransactionSystemClient(org.apache.tephra.TransactionSystemClient) Injector(com.google.inject.Injector) InMemoryStreamMetaStore(co.cask.cdap.data.stream.service.InMemoryStreamMetaStore) StreamMetaStore(co.cask.cdap.data.stream.service.StreamMetaStore) SystemDatasetRuntimeModule(co.cask.cdap.data.runtime.SystemDatasetRuntimeModule) DiscoveryRuntimeModule(co.cask.cdap.common.guice.DiscoveryRuntimeModule) NotificationFeedManager(co.cask.cdap.notifications.feeds.NotificationFeedManager) NoOpNotificationFeedManager(co.cask.cdap.notifications.feeds.service.NoOpNotificationFeedManager) AuthenticationContextModules(co.cask.cdap.security.auth.context.AuthenticationContextModules) DataSetsModules(co.cask.cdap.data.runtime.DataSetsModules) DefaultOwnerAdmin(co.cask.cdap.security.impersonation.DefaultOwnerAdmin) OwnerAdmin(co.cask.cdap.security.impersonation.OwnerAdmin) StreamCoordinatorClient(co.cask.cdap.data.stream.StreamCoordinatorClient) NonCustomLocationUnitTestModule(co.cask.cdap.common.guice.NonCustomLocationUnitTestModule) AuthorizationTestModule(co.cask.cdap.security.authorization.AuthorizationTestModule) AbstractModule(com.google.inject.AbstractModule) StreamAdminModules(co.cask.cdap.data.stream.StreamAdminModules) StreamAdmin(co.cask.cdap.data2.transaction.stream.StreamAdmin) StreamFileWriterFactory(co.cask.cdap.data.stream.StreamFileWriterFactory) ExploreClientModule(co.cask.cdap.explore.guice.ExploreClientModule) TransactionManager(org.apache.tephra.TransactionManager) QueueClientFactory(co.cask.cdap.data2.queue.QueueClientFactory) AuthorizationEnforcementModule(co.cask.cdap.security.authorization.AuthorizationEnforcementModule) BeforeClass(org.junit.BeforeClass)

Aggregations

QueueClientFactory (co.cask.cdap.data2.queue.QueueClientFactory)11 TransactionSystemClient (org.apache.tephra.TransactionSystemClient)8 ConfigModule (co.cask.cdap.common.guice.ConfigModule)7 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)7 DataSetsModules (co.cask.cdap.data.runtime.DataSetsModules)7 TransactionMetricsModule (co.cask.cdap.data.runtime.TransactionMetricsModule)7 AuthenticationContextModules (co.cask.cdap.security.auth.context.AuthenticationContextModules)7 AuthorizationEnforcementModule (co.cask.cdap.security.authorization.AuthorizationEnforcementModule)7 AuthorizationTestModule (co.cask.cdap.security.authorization.AuthorizationTestModule)7 TransactionExecutorFactory (org.apache.tephra.TransactionExecutorFactory)7 NonCustomLocationUnitTestModule (co.cask.cdap.common.guice.NonCustomLocationUnitTestModule)6 AbstractModule (com.google.inject.AbstractModule)6 BeforeClass (org.junit.BeforeClass)6 DefaultOwnerAdmin (co.cask.cdap.security.impersonation.DefaultOwnerAdmin)5 Injector (com.google.inject.Injector)5 SystemDatasetRuntimeModule (co.cask.cdap.data.runtime.SystemDatasetRuntimeModule)4 StreamAdminModules (co.cask.cdap.data.stream.StreamAdminModules)4 InMemoryStreamMetaStore (co.cask.cdap.data.stream.service.InMemoryStreamMetaStore)4 ViewAdminModules (co.cask.cdap.data.view.ViewAdminModules)4 ExploreClientModule (co.cask.cdap.explore.guice.ExploreClientModule)4