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);
}
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.
}
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());
}
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);
}
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)));
}
Aggregations