1   package eu.fbk.knowledgestore.datastore.hbase;
2   
3   import static eu.fbk.knowledgestore.datastore.hbase.utils.HBaseConstants.HBASE_ZOOKEEPER_CLIENT_PORT;
4   import static eu.fbk.knowledgestore.datastore.hbase.utils.HBaseConstants.HBASE_ZOOKEEPER_QUORUM;
5   import static eu.fbk.knowledgestore.datastore.hbase.utils.HBaseConstants.URIDICT_RELATIVEPATH_PROP;
6   
7   import java.io.IOException;
8   import java.util.List;
9   import java.util.Properties;
10  import java.util.concurrent.CancellationException;
11  
12  import org.apache.hadoop.fs.FileSystem;
13  import org.junit.Test;
14  
15  import eu.fbk.knowledgestore.data.Record;
16  import eu.fbk.knowledgestore.data.Stream;
17  import eu.fbk.knowledgestore.data.XPath;
18  import eu.fbk.knowledgestore.datastore.AbstractDataStoreTest;
19  import eu.fbk.knowledgestore.datastore.DataStore;
20  import eu.fbk.knowledgestore.datastore.DataTransaction;
21  import eu.fbk.knowledgestore.runtime.Files;
22  import eu.fbk.knowledgestore.vocabulary.KS;
23  
24  /**
25   * Class for testing the HBase data store
26   */
27  public class HBaseDataStoreTest extends AbstractDataStoreTest{
28  
29      @Override
30      protected DataStore createDataStore() {
31          final FileSystem fileSystem = Files.getRawLocalFileSystem();
32          final Properties properties = new Properties();
33          properties.setProperty(URIDICT_RELATIVEPATH_PROP, "uri" + System.nanoTime() + ".dic");
34          properties.setProperty(HBASE_ZOOKEEPER_QUORUM, "192.168.0.8");
35          properties.setProperty(HBASE_ZOOKEEPER_CLIENT_PORT, "2181");
36          return new HBaseDataStore(fileSystem, properties);
37      }
38  
39      @Test
40      public void testRetrieve() {
41          HBaseDataStore ds = (HBaseDataStore) new HBaseDataStoreTest().createDataStore();
42          try {
43              ds.init();
44              List<Record> records = createRecords(3, KS.RESOURCE);
45              DataTransaction dataTran = ds.begin(false);
46              dataTran.store(KS.RESOURCE, records.get(0));
47              dataTran.store(KS.RESOURCE,  records.get(1));
48              dataTran.delete(KS.RESOURCE, records.get(2).getID());
49              XPath condition = XPath.parse("'example.org'"); // TODO: I don't thing this will work
50              //condition.decompose(propertyRanges);
51              Stream<Record> cur = dataTran.retrieve(KS.RESOURCE, condition, null);
52              try {
53                  for (Record r : cur) {
54                      System.out.println(r);
55                  }
56              } finally {
57                  cur.close();
58              }
59          } catch (IOException e) {
60              // TODO Auto-generated catch block
61              e.printStackTrace();
62          } catch (CancellationException ex) {
63              // not our case: ignore
64          }
65      }
66  
67  }