List of usage examples for org.apache.hadoop.fs Path toString
@Override
public String toString()
From source file:com.ikanow.aleph2.core.shared.utils.TestClassloaderUtils.java
License:Apache License
@Test public void test_classLoading_primaryLib() throws UnsupportedFileSystemException { try {/* w w w . ja v a2s .c o m*/ Class.forName("com.ikanow.aleph2.test.example.ExampleHarvestTechnology"); assertTrue("Should have thrown a ClassNotFoundException", false); } catch (ClassNotFoundException e) { //expected! } final String pathname = System.getProperty("user.dir") + "/misc_test_assets/simple-harvest-example.jar"; final Path path = new Path(pathname); final Path path2 = FileContext.getLocalFSFileContext().makeQualified(path); final Validation<BasicMessageBean, IHarvestTechnologyModule> ret_val = ClassloaderUtils .getFromCustomClasspath(IHarvestTechnologyModule.class, "com.ikanow.aleph2.test.example.ExampleHarvestTechnology", Optional.of(path2.toString()), Collections.emptyList(), "test1", new TestMessageBean()); if (ret_val.isFail()) { System.out.println("About to crash with: " + ret_val.fail().message()); } assertEquals(true, ret_val.success() .canRunOnThisNode(BeanTemplateUtils.build(DataBucketBean.class).done().get(), null)); try { Class.forName("com.ikanow.aleph2.test.example.ExampleHarvestTechnology"); assertTrue("STILL! Should have thrown a ClassNotFoundException", false); } catch (ClassNotFoundException e) { //expected! } // Check if it gets cached: final Validation<BasicMessageBean, IHarvestTechnologyModule> ret_val_2 = ClassloaderUtils .getFromCustomClasspath(IHarvestTechnologyModule.class, "com.ikanow.aleph2.test.example.ExampleHarvestTechnology", Optional.of(path2.toString()), Collections.emptyList(), "test1", new TestMessageBean()); assertEquals(ret_val.success().getClass().getClassLoader(), ret_val_2.success().getClass().getClassLoader()); // Clear cache and check we get another classloader: ClassloaderUtils.clearCache(); final Validation<BasicMessageBean, IHarvestTechnologyModule> ret_val_3 = ClassloaderUtils .getFromCustomClasspath(IHarvestTechnologyModule.class, "com.ikanow.aleph2.test.example.ExampleHarvestTechnology", Optional.of(path2.toString()), Collections.emptyList(), "test1", new TestMessageBean()); assertNotEquals(ret_val.success().getClass().getClassLoader(), ret_val_3.success().getClass().getClassLoader()); }
From source file:com.ikanow.aleph2.core.shared.utils.TestClassloaderUtils.java
License:Apache License
@Test public void test_classLoading_secondaryLib() throws UnsupportedFileSystemException { try {//w w w .j ava2s. co m Class.forName("com.ikanow.aleph2.test.example.ExampleHarvestTechnology"); assertTrue("Should have thrown a ClassNotFoundException", false); } catch (ClassNotFoundException e) { //expected! } final String pathname = System.getProperty("user.dir") + "/misc_test_assets/simple-harvest-example.jar"; final Path path = new Path(pathname); final Path path2 = FileContext.getLocalFSFileContext().makeQualified(path); final Validation<BasicMessageBean, IHarvestTechnologyModule> ret_val = ClassloaderUtils .getFromCustomClasspath(IHarvestTechnologyModule.class, "com.ikanow.aleph2.test.example.ExampleHarvestTechnology", Optional.empty(), Arrays.asList(path2.toString()), "test1", new TestMessageBean()); if (ret_val.isFail()) { System.out.println("About to crash with: " + ret_val.fail().message()); } assertEquals(true, ret_val.success() .canRunOnThisNode(BeanTemplateUtils.build(DataBucketBean.class).done().get(), null)); try { Class.forName("com.ikanow.aleph2.test.example.ExampleHarvestTechnology"); assertTrue("STILL! Should have thrown a ClassNotFoundException", false); } catch (ClassNotFoundException e) { //expected! } }
From source file:com.ikanow.aleph2.core.shared.utils.TestClassloaderUtils.java
License:Apache License
@Test public void test_classLoading_fails() throws UnsupportedFileSystemException { try {// w w w .ja v a 2 s . c o m Class.forName("com.ikanow.aleph2.test.example.ExampleHarvestTechnology"); assertTrue("Should have thrown a ClassNotFoundException", false); } catch (ClassNotFoundException e) { //expected! } final String pathname = System.getProperty("user.dir") + "/simple-harvest-examplee-FAILS.jar"; final Path path = new Path(pathname); final Path path2 = FileContext.getLocalFSFileContext().makeQualified(path); final Validation<BasicMessageBean, IHarvestTechnologyModule> ret_val = ClassloaderUtils .getFromCustomClasspath(IHarvestTechnologyModule.class, "com.ikanow.aleph2.test.example.ExampleHarvestTechnology", Optional.empty(), Arrays.asList(path2.toString()), "test1", new TestMessageBean()); if (ret_val.isSuccess()) { System.out.println("About to crash,found class?"); } BasicMessageBean error = ret_val.fail(); assertEquals(error.command(), "TestMessageBean"); assertEquals((double) error.date().getTime(), (double) ((new Date()).getTime()), 1000.0); assertEquals(error.details(), null); final String expected_err_fragment = "Error loading class com.ikanow.aleph2.test.example.ExampleHarvestTechnology: [org.xeustechnologies.jcl.exception.JclException: java.lang.ClassNotFoundException: com.ikanow.aleph2.test.example.ExampleHarvestTechnology: RuntimeException]"; assertTrue("Failed error message, should contain: " + expected_err_fragment + " vs " + error.message(), error.message().contains(expected_err_fragment)); assertEquals(error.message_code(), null); assertEquals(error.source(), "test1"); assertEquals(error.success(), false); }
From source file:com.ikanow.aleph2.core.shared.utils.TestClassloaderUtils.java
License:Apache License
@Test public void test_classLoading_wrongInterface() throws UnsupportedFileSystemException { try {//w w w.j ava2s . c o m Class.forName("com.ikanow.aleph2.test.example.ExampleHarvestTechnology"); assertTrue("Should have thrown a ClassNotFoundException", false); } catch (ClassNotFoundException e) { //expected! } final String pathname = System.getProperty("user.dir") + "/misc_test_assets/simple-harvest-example.jar"; final Path path = new Path(pathname); final Path path2 = FileContext.getLocalFSFileContext().makeQualified(path); final Validation<BasicMessageBean, IHarvestTechnologyModule> ret_val = ClassloaderUtils .getFromCustomClasspath(IHarvestTechnologyModule.class, "java.lang.String", Optional.empty(), Arrays.asList(path2.toString()), "test1", new TestMessageBean()); if (ret_val.isSuccess()) { System.out.println("About to crash,found class?"); } BasicMessageBean error = ret_val.fail(); assertEquals(error.command(), "TestMessageBean"); assertEquals((double) error.date().getTime(), (double) ((new Date()).getTime()), 1000.0); assertEquals(error.details(), null); final String expected_err_fragment = "Error: class java.lang.String is not an implementation of interface"; assertTrue("Failed error message, should contain: " + expected_err_fragment + " vs " + error.message(), error.message().contains(expected_err_fragment)); assertEquals(error.message_code(), null); assertEquals(error.source(), "test1"); assertEquals(error.success(), false); }
From source file:com.ikanow.aleph2.core.shared.utils.TestJarCacheUtils.java
License:Apache License
@Test public void test_localFileNotPresent() throws InterruptedException, ExecutionException, UnsupportedFileSystemException { final FileContext localfs = FileContext.getLocalFSFileContext(new Configuration()); final String local_cached_dir = Optional.of(_globals.local_cached_jar_dir()) .map(dir -> dir.replace(File.separator, "/")).map(dir -> dir.endsWith("/") ? dir : (dir + "/")) .get();/*from w w w. java2s . com*/ final String expected_cache_name = local_cached_dir + "test1.cache.jar"; final Path expected_cache_path = localfs.makeQualified(new Path(expected_cache_name)); // Just make sure we've deleted the old file try { new File(expected_cache_name).delete(); } catch (Exception e) { } assertTrue("Remote file exists", new File(_test_file_path).exists()); assertFalse("Local file doesn't exist", new File(expected_cache_name).exists()); final SharedLibraryBean library_bean = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::path_name, _test_file_path).with(SharedLibraryBean::_id, "test1").done() .get(); final Validation<BasicMessageBean, String> ret_val_1 = JarCacheUtils.getCachedJar( _globals.local_cached_jar_dir(), library_bean, _mock_hdfs, "test1", new TestMessageBean()).get(); assertEquals(expected_cache_path.toString(), ret_val_1.success()); assertTrue("Local file now exists", new File(expected_cache_name).exists()); }
From source file:com.ikanow.aleph2.core.shared.utils.TestJarCacheUtils.java
License:Apache License
@Test public void test_localFilePresentButOld() throws InterruptedException, ExecutionException, AccessControlException, FileAlreadyExistsException, FileNotFoundException, ParentNotDirectoryException, IOException { final FileContext localfs = FileContext.getLocalFSFileContext(new Configuration()); String java_name = _globals.local_cached_jar_dir() + File.separator + "testX.cache.jar"; final String expected_cache_name = java_name.replace(File.separator, "/"); final Path expected_cache_path = localfs.makeQualified(new Path(expected_cache_name)); // Just make sure we've deleted the old file try {/* w ww . jav a 2 s. com*/ System.out.println("Deleted: " + new File(java_name).delete()); } catch (Exception e) { fail("Misc Error: " + e); } assertTrue("Remote file exists", new File(_test_file_path).exists()); assertFalse("Local file doesn't exist: " + java_name, new File(java_name).exists()); // Now create the file localfs.create(expected_cache_path, EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE)); localfs.setTimes(expected_cache_path, 0L, 0L); // check something has happened: assertEquals(0L, localfs.getFileStatus(expected_cache_path).getModificationTime()); assertNotEquals(0L, _test_file_time); // Now run the test routine final SharedLibraryBean library_bean = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::path_name, _test_file_path).with(SharedLibraryBean::_id, "testX").done() .get(); final Validation<BasicMessageBean, String> ret_val_1 = JarCacheUtils.getCachedJar( _globals.local_cached_jar_dir(), library_bean, _mock_hdfs, "testX", new TestMessageBean()).get(); assertEquals(expected_cache_path.toString(), ret_val_1.success()); assertTrue("Local file still exists", new File(expected_cache_name).exists()); assertTrue("File time should have been updated", localfs.getFileStatus(expected_cache_path).getModificationTime() >= _test_file_time); }
From source file:com.ikanow.aleph2.core.shared.utils.TestJarCacheUtils.java
License:Apache License
@Test public void test_localFilePresentAndNew() throws InterruptedException, ExecutionException, AccessControlException, FileAlreadyExistsException, FileNotFoundException, ParentNotDirectoryException, IOException { final FileContext localfs = FileContext.getLocalFSFileContext(new Configuration()); final String expected_cache_name = _globals.local_cached_jar_dir().replace(File.separator, "/") + "test1.cache.jar"; final Path expected_cache_path = localfs.makeQualified(new Path(expected_cache_name)); // Just make sure we've deleted the old file try {/*from w ww . j ava 2 s . c o m*/ new File(expected_cache_name).delete(); } catch (Exception e) { } assertTrue("Remote file exists", new File(_test_file_path).exists()); assertFalse("Local file doesn't exist", new File(expected_cache_name).exists()); // Now create the file localfs.create(expected_cache_path, EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE)); localfs.setTimes(expected_cache_path, _test_file_time + 10000, _test_file_time + 10000); // check something has happened: assertEquals(_test_file_time + 10000, localfs.getFileStatus(expected_cache_path).getModificationTime()); // Now run the test routine final SharedLibraryBean library_bean = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::path_name, _test_file_path).with(SharedLibraryBean::_id, "test1").done() .get(); final Validation<BasicMessageBean, String> ret_val_1 = JarCacheUtils.getCachedJar( _globals.local_cached_jar_dir(), library_bean, _mock_hdfs, "test1", new TestMessageBean()).get(); assertEquals(expected_cache_path.toString(), ret_val_1.success()); assertTrue("Local file still exists", new File(expected_cache_name).exists()); assertEquals(localfs.getFileStatus(expected_cache_path).getModificationTime(), _test_file_time + 10000); }
From source file:com.ikanow.aleph2.data_import_manager.analytics.actors.TestDataBucketChangeActor.java
License:Apache License
protected List<SharedLibraryBean> createSharedLibraryBeans_analytics(Path path1, Path path2) { final SharedLibraryBean lib_element = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "test_tech_id_analytics") .with(SharedLibraryBean::path_name, path1.toString()).with(SharedLibraryBean::misc_entry_point, "com.ikanow.aleph2.test.example.ExampleAnalyticsTechnology") .done().get();// w w w. j a va2s . co m final SharedLibraryBean lib_element2 = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "test_module_id").with(SharedLibraryBean::path_name, path2.toString()) .done().get(); final SharedLibraryBean lib_element3 = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "failtest") .with(SharedLibraryBean::path_name, "/not_exist/here.fghgjhgjhg").done().get(); return Arrays.asList(lib_element, lib_element2, lib_element3); }
From source file:com.ikanow.aleph2.data_import_manager.analytics.actors.TestDataBucketChangeActor.java
License:Apache License
protected List<SharedLibraryBean> createSharedLibraryBeans_batch(Path path1, Path path2) { final SharedLibraryBean lib_element = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "test_tech_id_batch") .with(SharedLibraryBean::path_name, path1.toString()).with(SharedLibraryBean::misc_entry_point, "com.ikanow.aleph2.analytics.hadoop.assets.BePassthroughModule") .done().get();// w ww .ja va2s. c om final SharedLibraryBean lib_element2 = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "test_module_id").with(SharedLibraryBean::path_name, path2.toString()) .done().get(); final SharedLibraryBean lib_element3 = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "failtest") .with(SharedLibraryBean::path_name, "/not_exist/here.fghgjhgjhg").done().get(); // (result in classloader error) final SharedLibraryBean lib_element4 = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "test_tech_id_batch_fail") .with(SharedLibraryBean::path_name, path1.toString()) .with(SharedLibraryBean::batch_enrichment_entry_point, "com.ikanow.aleph2.test.example.ExampleBatchTopology") .done().get(); return Arrays.asList(lib_element, lib_element2, lib_element3, lib_element4); }
From source file:com.ikanow.aleph2.data_import_manager.analytics.actors.TestDataBucketChangeActor.java
License:Apache License
protected List<SharedLibraryBean> createSharedLibraryBeans_streaming(Path path1, Path path2) { final SharedLibraryBean lib_element = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "test_tech_id_stream") .with(SharedLibraryBean::path_name, path1.toString()).with(SharedLibraryBean::misc_entry_point, "com.ikanow.aleph2.data_import.stream_enrichment.storm.PassthroughTopology") .done().get();/* w w w .jav a2s.c o m*/ final SharedLibraryBean lib_element2 = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "test_module_id").with(SharedLibraryBean::path_name, path2.toString()) .done().get(); final SharedLibraryBean lib_element3 = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "failtest") .with(SharedLibraryBean::path_name, "/not_exist/here.fghgjhgjhg").done().get(); // (result in classloader error) final SharedLibraryBean lib_element4 = BeanTemplateUtils.build(SharedLibraryBean.class) .with(SharedLibraryBean::_id, "test_tech_id_stream_fail") .with(SharedLibraryBean::path_name, path1.toString()) .with(SharedLibraryBean::streaming_enrichment_entry_point, "com.ikanow.aleph2.test.example.ExampleStreamTopology") .done().get(); return Arrays.asList(lib_element, lib_element2, lib_element3, lib_element4); }