Search in sources :

Example 31 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory in project cdap by caskdata.

the class DefaultNamespacedLocationFactoryTest method testGet.

@Test
public void testGet() throws Exception {
    File locationFactoryPath = TEMP_FOLDER.newFolder();
    LocationFactory locationFactory = new LocalLocationFactory(locationFactoryPath);
    NamespaceAdmin nsAdmin = new InMemoryNamespaceClient();
    NamespaceId ns1 = new NamespaceId("ns1");
    NamespaceMeta defaultNSMeta = new NamespaceMeta.Builder().setName(Id.Namespace.DEFAULT).build();
    NamespaceMeta ns1NSMeta = new NamespaceMeta.Builder().setName(ns1).setRootDirectory("/ns1").build();
    nsAdmin.create(defaultNSMeta);
    nsAdmin.create(ns1NSMeta);
    CConfiguration cConf = CConfiguration.create();
    NamespacedLocationFactory namespacedLocationFactory = new DefaultNamespacedLocationFactory(cConf, locationFactory, nsAdmin);
    Location defaultLoc = namespacedLocationFactory.get(NamespaceId.DEFAULT);
    Location ns1Loc = namespacedLocationFactory.get(ns1);
    // check if location was as expected
    Location expectedLocation = locationFactory.create(cConf.get(Constants.Namespace.NAMESPACES_DIR)).append(NamespaceId.DEFAULT.getNamespace());
    Assert.assertEquals(expectedLocation, defaultLoc);
    expectedLocation = Locations.getLocationFromAbsolutePath(locationFactory, "/ns1");
    Assert.assertEquals(expectedLocation, ns1Loc);
    // test these are not the same
    Assert.assertNotEquals(defaultLoc, ns1Loc);
    // test subdirectories in a namespace
    Location sub1 = namespacedLocationFactory.get(ns1).append("sub1");
    Location sub2 = namespacedLocationFactory.get(ns1).append("sub2");
    Assert.assertNotEquals(sub1, sub2);
}
Also used : CConfiguration(co.cask.cdap.common.conf.CConfiguration) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) File(java.io.File) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 32 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory in project cdap by caskdata.

the class ClassLoaderTest method testWeakReferenceClassLoader.

@Test
public void testWeakReferenceClassLoader() throws Exception {
    // Creates a jar that has Application class in it.
    Location jar = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), ClassLoaderTest.class);
    // Create a class loader that load from that jar.
    File unpackDir = TMP_FOLDER.newFolder();
    BundleJarUtil.unJar(jar, unpackDir);
    ClassLoader cl = new DirectoryClassLoader(unpackDir, null, "lib");
    // Wrap it with the WeakReference ClassLoader
    ClassLoader classLoader = new WeakReferenceDelegatorClassLoader(cl);
    // Load class from the wrapped ClassLoader, should succeed and should be loaded by the delegating ClassLoader.
    Class<?> cls = classLoader.loadClass(ClassLoaderTest.class.getName());
    Assert.assertSame(cl, cls.getClassLoader());
    Assert.assertSame(cl, Delegators.getDelegate(classLoader, ClassLoader.class));
// There is no good way to test the GC of the weak reference referent since it depends on GC.
}
Also used : LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) File(java.io.File) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 33 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory in project cdap by caskdata.

the class DatasetServiceTestBase method initialize.

protected static void initialize() throws Exception {
    locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
    initializeAndStartService(createCConf());
}
Also used : LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory)

Example 34 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory in project cdap by caskdata.

the class DatasetServiceTestBase method createModuleJar.

protected Location createModuleJar(Class moduleClass, Location... bundleEmbeddedJars) throws IOException {
    LocationFactory lf = new LocalLocationFactory(TMP_FOLDER.newFolder());
    File[] embeddedJars = new File[bundleEmbeddedJars.length];
    for (int i = 0; i < bundleEmbeddedJars.length; i++) {
        File file = TMP_FOLDER.newFile();
        Files.copy(Locations.newInputSupplier(bundleEmbeddedJars[i]), file);
        embeddedJars[i] = file;
    }
    return AppJarHelper.createDeploymentJar(lf, moduleClass, embeddedJars);
}
Also used : LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) File(java.io.File) NamespacedLocationFactory(co.cask.cdap.common.namespace.NamespacedLocationFactory) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory)

Example 35 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory in project cdap by caskdata.

the class StreamUtilsTest method testStreamIdFromLocation.

@Test
public void testStreamIdFromLocation() {
    LocationFactory locationFactory = new LocalLocationFactory();
    String path = "/cdap/namespaces/default/streams/fooStream";
    Location streamBaseLocation = locationFactory.create(path);
    StreamId expectedId = NamespaceId.DEFAULT.stream("fooStream");
    Assert.assertEquals(expectedId, new StreamId("default", StreamUtils.getStreamNameFromLocation(streamBaseLocation)));
    path = "/customLocation/streams/otherstream";
    streamBaseLocation = locationFactory.create(path);
    expectedId = new StreamId("othernamespace", "otherstream");
    Assert.assertEquals(expectedId, new StreamId("othernamespace", StreamUtils.getStreamNameFromLocation(streamBaseLocation)));
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Aggregations

LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)41 Location (org.apache.twill.filesystem.Location)29 LocationFactory (org.apache.twill.filesystem.LocationFactory)21 File (java.io.File)15 CConfiguration (co.cask.cdap.common.conf.CConfiguration)11 BeforeClass (org.junit.BeforeClass)11 Test (org.junit.Test)11 NamespacedLocationFactory (co.cask.cdap.common.namespace.NamespacedLocationFactory)5 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)4 NamespaceAdmin (co.cask.cdap.common.namespace.NamespaceAdmin)4 ArtifactRepository (co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository)4 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)4 Injector (com.google.inject.Injector)4 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)3 URL (java.net.URL)3 CloseableClassLoader (co.cask.cdap.api.artifact.CloseableClassLoader)2 ConfigResponse (co.cask.cdap.app.deploy.ConfigResponse)2 Configurator (co.cask.cdap.app.deploy.Configurator)2 DummyProgramRunnerFactory (co.cask.cdap.app.runtime.DummyProgramRunnerFactory)2 StreamAdmin (co.cask.cdap.data2.transaction.stream.StreamAdmin)2