Search in sources :

Example 1 with MockTwillContext

use of io.cdap.cdap.common.test.MockTwillContext in project cdap by caskdata.

the class SparkTwillRunnableModuleTest method testSpark.

@Test
public void testSpark() {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").spark("spark").run(RunIds.generate());
    for (ClusterMode mode : ClusterMode.values()) {
        Module module = new SparkTwillRunnable("spark") {

            @Override
            protected ServiceAnnouncer getServiceAnnouncer() {
                return new MockTwillContext();
            }
        }.createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
        Injector injector = Guice.createInjector(module);
        injector.getInstance(SparkProgramRunner.class);
        injector.getInstance(ExploreClient.class);
        Injector contextInjector = SparkRuntimeContextProvider.createInjector(CConfiguration.create(), new Configuration(), programRunId.getParent(), createProgramOptions(programRunId, mode));
        contextInjector.getInstance(PluginFinder.class);
        contextInjector.getInstance(ExploreClient.class);
    }
}
Also used : MockTwillContext(io.cdap.cdap.common.test.MockTwillContext) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) Injector(com.google.inject.Injector) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Module(com.google.inject.Module) ServiceAnnouncer(org.apache.twill.api.ServiceAnnouncer) Test(org.junit.Test)

Example 2 with MockTwillContext

use of io.cdap.cdap.common.test.MockTwillContext in project cdap by caskdata.

the class ProgramTwillRunnableModuleTest method testService.

@Test
public void testService() {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").service("service").run(RunIds.generate());
    for (ClusterMode mode : ClusterMode.values()) {
        Module module = new ServiceTwillRunnable("service") {

            @Override
            protected ServiceAnnouncer getServiceAnnouncer() {
                return new MockTwillContext();
            }
        }.createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
        Injector injector = Guice.createInjector(module);
        injector.getInstance(ServiceProgramRunner.class);
        injector.getInstance(ExploreClient.class);
    }
}
Also used : MockTwillContext(io.cdap.cdap.common.test.MockTwillContext) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) Injector(com.google.inject.Injector) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Module(com.google.inject.Module) ServiceAnnouncer(org.apache.twill.api.ServiceAnnouncer) Test(org.junit.Test)

Example 3 with MockTwillContext

use of io.cdap.cdap.common.test.MockTwillContext in project cdap by caskdata.

the class DistributedLogFrameworkTest method createInjector.

private Injector createInjector() throws IOException {
    CConfiguration cConf = CConfiguration.copy(KAFKA_TESTER.getCConf());
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    // The event delay cannot be too small, otherwise the events will be out of order, especially on slow machine
    cConf.setLong(Constants.Logging.PIPELINE_EVENT_DELAY_MS, 2000);
    cConf.setLong("log.process.pipeline.checkpoint.interval.ms", 2000);
    MockTwillContext mockTwillContext = new MockTwillContext();
    return Guice.createInjector(new ConfigModule(cConf), new ZKClientModule(), new InMemoryDiscoveryModule(), new KafkaClientModule(), new LocalLocationModule(), new DistributedLogFrameworkModule(mockTwillContext.getInstanceId(), mockTwillContext.getInstanceCount()), new DataSetsModules().getInMemoryModules(), new TransactionModules().getInMemoryModules(), new TransactionExecutorModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new NamespaceAdminTestModule(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new StorageModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
            bind(UGIProvider.class).to(CurrentUGIProvider.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
        }
    });
}
Also used : MockTwillContext(io.cdap.cdap.common.test.MockTwillContext) InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) StorageModule(io.cdap.cdap.data.runtime.StorageModule) NamespaceAdminTestModule(io.cdap.cdap.common.guice.NamespaceAdminTestModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) DataSetsModules(io.cdap.cdap.data.runtime.DataSetsModules) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) DefaultOwnerAdmin(io.cdap.cdap.security.impersonation.DefaultOwnerAdmin) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AuthorizationTestModule(io.cdap.cdap.security.authorization.AuthorizationTestModule) AbstractModule(com.google.inject.AbstractModule) TransactionModules(org.apache.tephra.runtime.TransactionModules) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) TransactionExecutorModule(io.cdap.cdap.data.runtime.TransactionExecutorModule) LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) KafkaClientModule(io.cdap.cdap.common.guice.KafkaClientModule) DistributedLogFrameworkModule(io.cdap.cdap.logging.guice.DistributedLogFrameworkModule) CurrentUGIProvider(io.cdap.cdap.security.impersonation.CurrentUGIProvider) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule)

Aggregations

CConfiguration (io.cdap.cdap.common.conf.CConfiguration)3 MockTwillContext (io.cdap.cdap.common.test.MockTwillContext)3 Injector (com.google.inject.Injector)2 Module (com.google.inject.Module)2 ClusterMode (io.cdap.cdap.app.guice.ClusterMode)2 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)2 Configuration (org.apache.hadoop.conf.Configuration)2 ServiceAnnouncer (org.apache.twill.api.ServiceAnnouncer)2 Test (org.junit.Test)2 AbstractModule (com.google.inject.AbstractModule)1 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)1 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)1 KafkaClientModule (io.cdap.cdap.common.guice.KafkaClientModule)1 LocalLocationModule (io.cdap.cdap.common.guice.LocalLocationModule)1 NamespaceAdminTestModule (io.cdap.cdap.common.guice.NamespaceAdminTestModule)1 ZKClientModule (io.cdap.cdap.common.guice.ZKClientModule)1 NoOpMetricsCollectionService (io.cdap.cdap.common.metrics.NoOpMetricsCollectionService)1 DataSetsModules (io.cdap.cdap.data.runtime.DataSetsModules)1 StorageModule (io.cdap.cdap.data.runtime.StorageModule)1 SystemDatasetRuntimeModule (io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule)1