Search in sources :

Example 71 with AppRequest

use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.

the class TestFrameworkTestRun method testAppVersionsCreation.

@Test
public void testAppVersionsCreation() throws Exception {
    ArtifactId artifactId = new ArtifactId(NamespaceId.DEFAULT.getNamespace(), "cfg-app", "1.0.0-SNAPSHOT");
    addAppArtifact(artifactId, ConfigTestApp.class);
    ApplicationId appId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "AppV1", "version1");
    AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("tS1", "tD1", "tV1"));
    ApplicationManager appManager = deployApplication(appId, createRequest);
    ServiceManager serviceManager = appManager.getServiceManager(ConfigTestApp.SERVICE_NAME);
    serviceManager.start();
    URL serviceURL = serviceManager.getServiceURL();
    Gson gson = new Gson();
    Assert.assertEquals("tV1", gson.fromJson(callServiceGet(serviceURL, "ping"), String.class));
    serviceManager.stop();
    appId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "AppV1", "version2");
    createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("tS2", "tD2", "tV2"));
    appManager = deployApplication(appId, createRequest);
    serviceManager = appManager.getServiceManager(ConfigTestApp.SERVICE_NAME);
    serviceManager.start();
    serviceURL = serviceManager.getServiceURL();
    Assert.assertEquals("tV2", gson.fromJson(callServiceGet(serviceURL, "ping"), String.class));
    serviceManager.stop();
}
Also used : ApplicationManager(co.cask.cdap.test.ApplicationManager) ArtifactId(co.cask.cdap.proto.id.ArtifactId) Gson(com.google.gson.Gson) URL(java.net.URL) AppRequest(co.cask.cdap.proto.artifact.AppRequest) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ServiceManager(co.cask.cdap.test.ServiceManager) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ConfigTestApp(co.cask.cdap.ConfigTestApp) Test(org.junit.Test)

Example 72 with AppRequest

use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.

the class TestFrameworkTestRun method testInvalidAppWithDuplicateDatasets.

@Test
public void testInvalidAppWithDuplicateDatasets() throws Exception {
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("invalid-app", "1.0.0-SNAPSHOT");
    addAppArtifact(artifactId, AppWithDuplicateData.class);
    ArtifactId pluginArtifactId = NamespaceId.DEFAULT.artifact("test-plugin", "1.0.0-SNAPSHOT");
    addPluginArtifact(pluginArtifactId, artifactId, ToStringPlugin.class);
    ApplicationId appId = NamespaceId.DEFAULT.app("InvalidApp");
    for (int choice = 4; choice > 0; choice /= 2) {
        try {
            AppRequest<AppWithDuplicateData.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new AppWithDuplicateData.ConfigClass((choice == 4), (choice == 2), (choice == 1)));
            deployApplication(appId, createRequest);
            // fail if we succeed with application deployment
            Assert.fail();
        } catch (Exception e) {
        // expected
        }
    }
    AppRequest<AppWithDuplicateData.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new AppWithDuplicateData.ConfigClass(false, false, false));
    deployApplication(appId, createRequest);
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ConflictException(co.cask.cdap.common.ConflictException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 73 with AppRequest

use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.

the class UnitTestManager method deployApplication.

@Override
public ApplicationManager deployApplication(NamespaceId namespace, Class<? extends Application> applicationClz, @Nullable Config configObject, File... bundleEmbeddedJars) {
    Preconditions.checkNotNull(applicationClz, "Application class cannot be null.");
    Type configType = Artifacts.getConfigType(applicationClz);
    try {
        ArtifactId artifactId = new ArtifactId(namespace.getNamespace(), applicationClz.getSimpleName(), "1.0-SNAPSHOT");
        addAppArtifact(artifactId, applicationClz);
        if (configObject == null) {
            configObject = (Config) TypeToken.of(configType).getRawType().newInstance();
        }
        Application app = applicationClz.newInstance();
        MockAppConfigurer configurer = new MockAppConfigurer(app);
        app.configure(configurer, new DefaultApplicationContext<>(configObject));
        ApplicationId applicationId = new ApplicationId(namespace.getNamespace(), configurer.getName());
        ArtifactSummary artifactSummary = new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion());
        appFabricClient.deployApplication(applicationId.toId(), new AppRequest(artifactSummary, configObject));
        return appManagerFactory.create(applicationId);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Type(java.lang.reflect.Type) MockAppConfigurer(co.cask.cdap.app.MockAppConfigurer) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Application(co.cask.cdap.api.app.Application) TransactionFailureException(org.apache.tephra.TransactionFailureException) IOException(java.io.IOException) AppRequest(co.cask.cdap.proto.artifact.AppRequest)

Aggregations

AppRequest (co.cask.cdap.proto.artifact.AppRequest)73 ApplicationId (co.cask.cdap.proto.id.ApplicationId)68 Test (org.junit.Test)46 ApplicationManager (co.cask.cdap.test.ApplicationManager)44 ETLStage (co.cask.cdap.etl.proto.v2.ETLStage)39 StructuredRecord (co.cask.cdap.api.data.format.StructuredRecord)31 Schema (co.cask.cdap.api.data.schema.Schema)29 Table (co.cask.cdap.api.dataset.table.Table)29 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)28 ETLBatchConfig (co.cask.cdap.etl.proto.v2.ETLBatchConfig)27 WorkflowManager (co.cask.cdap.test.WorkflowManager)27 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)21 ArtifactId (co.cask.cdap.proto.id.ArtifactId)16 Id (co.cask.cdap.proto.Id)14 NamespaceId (co.cask.cdap.proto.id.NamespaceId)13 ProgramId (co.cask.cdap.proto.id.ProgramId)13 HashSet (java.util.HashSet)13 TimeoutException (java.util.concurrent.TimeoutException)11 ArrayList (java.util.ArrayList)9 DataStreamsConfig (co.cask.cdap.etl.proto.v2.DataStreamsConfig)8