private void close() throws Exception { //It is very important to close the datastore properly, otherwise //some data loss might occur. if(dataStore != null) dataStore.close(); }
@Override public void close(TaskAttemptContext context) throws IOException, InterruptedException { try{ store.close(); }catch(Exception e){ LOG.warn("Exception at GoraRecordWriter.class while closing datastore: {}", e.getMessage()); LOG.warn("Trace: {}", e.getStackTrace()); throw new RuntimeException(e); } }
@Override public void close(TaskAttemptContext context) throws IOException, InterruptedException { try{ store.close(); }catch(Exception e){ LOG.warn("Exception at GoraRecordWriter.class while closing datastore: {}", e.getMessage()); LOG.warn("Trace: {}", e.getStackTrace()); throw new RuntimeException(e); } }
/** * <p> * If the {@link org.apache.gora.store.DataStore} instance is not null, we * execute a {@link org.apache.gora.store.DataStore#flush()}. This forces * the write caches to be flushed. DataStore implementations may optimize * their writing by deferring the actual put / delete operations until * this moment. * </p> * <p>Otherwise, we utilize {@link org.apache.gora.store.DataStore#close()} * which closes the DataStore. This should release any resources held by * the implementation, so that the instance is ready for GC. All other * DataStore methods cannot be used after this method was called. * Subsequent calls of this method are ignored. * </p> * @see org.apache.hadoop.chukwa.datacollection.writer.ChukwaWriter#close() */ @Override public void close() throws WriterException { if (chunkStore != null) { chunkStore.flush(); } else { chunkStore.close(); } log.debug("Gora datastore successfully closed."); }
@Override public void tearDown() throws Exception { LOG.info("Tearing down Hadoop Test Case..."); webPageStore.close(); super.tearDown(); }
/** Should be called once after each test, probably in the * method annotated with org.junit.After */ @SuppressWarnings("rawtypes") public void tearDown() throws Exception { log.info("tearing down test"); //delete everything for(DataStore store : dataStores) { try { store.deleteSchema(); store.close(); }catch (Exception ignore) { } } dataStores.clear(); }
@Override public void close() { flush(); cacheEntryList.clear(); if (!cache.isDestroyed() && !manager.isClosed()) { cache.close(); } if (!manager.isClosed()) { manager.close(); } hazelcastInstance.shutdown(); persistentDataStore.close(); LOG.info("JCache Gora datastore destroyed successfully."); }
@Override public void close() { try{ flush(); } catch (GoraException e) { LOG.error(e.getMessage(), e); if (e.getCause() != null) { LOG.error(e.getCause().getMessage()); } // At this point, the exception is ignored... } cacheEntryList.clear(); if (!cache.isDestroyed() && !manager.isClosed()) { cache.close(); } if (!manager.isClosed()) { manager.close(); } hazelcastInstance.shutdown(); persistentDataStore.close(); LOG.info("JCache Gora datastore destroyed successfully."); }
public static byte[] testPutBytes(DataStore<String, WebPage> store) throws Exception { store.createSchema(); WebPage page = WebPage.newBuilder().build(); page.setUrl(new Utf8("http://example.com")); byte[] contentBytes = "example content in example.com".getBytes(Charset.defaultCharset()); ByteBuffer buff = ByteBuffer.wrap(contentBytes); page.setContent(buff); store.put("com.example/http", page); store.close(); return contentBytes; }
@Test public void testGetMissingValue() throws GoraException { DataStore<String, WebPage> store = new MemStore<>(); WebPage nullWebPage = store.get("missing", new String[0]); assertNull(nullWebPage); store.close(); }
/** * Tests by running the {@link org.apache.gora.examples.mapreduce.QueryCounter} * mapreduce job */ public static void testCountQuery(DataStore<String, WebPage> dataStore, Configuration conf) throws Exception { ((DataStoreBase<String, WebPage>)dataStore).setConf(conf); //create input WebPageDataCreator.createWebPageData(dataStore); QueryCounter<String,WebPage> counter = new QueryCounter<>(conf); Query<String,WebPage> query = dataStore.newQuery(); List<Field> fields = WebPage.SCHEMA$.getFields(); String[] fieldNames = new String[fields.size() - 1]; for(int i = 0; i< fieldNames.length; i++){ fieldNames[i] = fields.get(i+1).name(); } query.setFields(fieldNames); dataStore.close(); //run the job log.info("running count query job"); long result = counter.countQuery(query); log.info("finished count query job"); //assert results assertEquals(WebPageDataCreator.URLS.length, result); }
public static void testPutArray(DataStore<String, WebPage> store) throws Exception { store.createSchema(); WebPage page = WebPage.newBuilder().build(); String[] tokens = {"example", "content", "in", "example.com"}; page.setParsedContent(new ArrayList<CharSequence>()); for(String token: tokens) { page.getParsedContent().add(new Utf8(token)); } store.put("com.example/http", page); store.close(); }
public static void testPutMap(DataStore<String, WebPage> store) throws Exception { store.createSchema(); WebPage page = WebPage.newBuilder().build(); page.setUrl(new Utf8("http://example.com")); page.getOutlinks().put(new Utf8("http://example2.com"), new Utf8("anchor2")); page.getOutlinks().put(new Utf8("http://example3.com"), new Utf8("anchor3")); page.getOutlinks().put(new Utf8("http://example3.com"), new Utf8("anchor4")); store.put("com.example/http", page); store.close(); }
@Test public void testPutGet() throws Exception { String key = "org.apache.gora:http:/"; DataStore<String, WebPage> store = new MemStore<>(); assumeTrue(store.get(key, new String[0]) == null); store.put(key, WebPage.newBuilder().build()); assertNotNull(store.get(key, new String[0])); store.close(); }