Example #1
0
  public void doIt() throws InterruptedException, ExecutionException {
    FetchBucketPropsOperation bpOp =
        new FetchBucketPropsOperation.Builder(BinaryValue.unsafeCreate("test_bucket3)".getBytes()))
            .withBucketType(BinaryValue.unsafeCreate("test_type2".getBytes()))
            .build();

    cluster.execute(bpOp);
    BucketProperties props = bpOp.get();
    System.out.println(props);

    FetchOperation fetchOp =
        new FetchOperation.Builder(
                BinaryValue.unsafeCreate("test_bucket2".getBytes()),
                BinaryValue.unsafeCreate("test_key2".getBytes()))
            .build();

    // fetchOp.addListener(this);
    cluster.execute(fetchOp);
    FetchOperation.Response resp = fetchOp.get();
    System.out.println(resp.isNotFound());
    for (RiakObject ro : resp.getObjectList()) {
      System.out.println("value: " + ro.getValue());
      System.out.println(ro.isDeleted());
    }
    cluster.shutdown();
  }
Example #2
0
  @Override
  public void handle(RiakFuture<RiakObject> f) {
    try {
      RiakObject ro = f.get();
      System.out.println("value: " + ro.getValue());
      System.out.println(ro.isDeleted());

      cluster.shutdown();
    } catch (InterruptedException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ExecutionException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  @Test
  public void testBasicMR() throws InterruptedException, ExecutionException, IOException {
    RiakObject obj = new RiakObject();

    obj.setValue(
        ByteArrayWrapper.create(
            "Alice was beginning to get very tired of sitting by her sister on the "
                + "bank, and of having nothing to do: once or twice she had peeped into the "
                + "book her sister was reading, but it had no pictures or conversations in "
                + "it, 'and what is the use of a book,' thought Alice 'without pictures or "
                + "conversation?'"));

    StoreOperation storeOp =
        new StoreOperation.Builder(bucketName)
            .withKey(ByteArrayWrapper.unsafeCreate("p1".getBytes()))
            .withContent(obj)
            .build();

    cluster.execute(storeOp);
    storeOp.get();

    obj.setValue(
        ByteArrayWrapper.create(
            "So she was considering in her own mind (as well as she could, for the "
                + "hot day made her feel very sleepy and stupid), whether the pleasure "
                + "of making a daisy-chain would be worth the trouble of getting up and "
                + "picking the daisies, when suddenly a White Rabbit with pink eyes ran "
                + "close by her."));

    storeOp =
        new StoreOperation.Builder(bucketName)
            .withKey(ByteArrayWrapper.unsafeCreate("p2".getBytes()))
            .withContent(obj)
            .build();

    cluster.execute(storeOp);
    storeOp.get();

    obj.setValue(
        ByteArrayWrapper.create(
            "The rabbit-hole went straight on like a tunnel for some way, and then "
                + "dipped suddenly down, so suddenly that Alice had not a moment to think "
                + "about stopping herself before she found herself falling down a very deep "
                + "well."));

    storeOp =
        new StoreOperation.Builder(bucketName)
            .withKey(ByteArrayWrapper.unsafeCreate("p3".getBytes()))
            .withContent(obj)
            .build();

    cluster.execute(storeOp);
    storeOp.get();

    String bName = bucketName.toString();
    String query =
        "{\"inputs\":[[\""
            + bName
            + "\",\"p1\"],[\""
            + bName
            + "\",\"p2\"],[\""
            + bName
            + "\",\"p3\"]],"
            + "\"query\":[{\"map\":{\"language\":\"javascript\",\"source\":\""
            + "function(v) {var m = v.values[0].data.toLowerCase().match(/\\w*/g); var r = [];"
            + "for(var i in m) {if(m[i] != '') {var o = {};o[m[i]] = 1;r.push(o);}}return r;}"
            + "\"}},{\"reduce\":{\"language\":\"javascript\",\"source\":\""
            + "function(v) {var r = {};for(var i in v) {for(var w in v[i]) {if(w in r) r[w] += v[i][w];"
            + "else r[w] = v[i][w];}}return [r];}\"}}]}";

    MapReduceOperation mrOp =
        new MapReduceOperation(ByteArrayWrapper.unsafeCreate(query.getBytes()), "application/json");

    cluster.execute(mrOp);
    List<ByteArrayWrapper> resultList = mrOp.get();

    // The query should return one result which is a JSON array containing a
    // single JSON object that is a set of word counts.
    assertEquals(resultList.size(), 1);

    String json = resultList.get(0).toString();
    ObjectMapper oMapper = new ObjectMapper();
    @SuppressWarnings("unchecked")
    List<Map<String, Integer>> jsonList = oMapper.readValue(json, List.class);
    Map<String, Integer> resultMap = jsonList.get(0);

    assertNotNull(resultMap.containsKey("the"));
    assertEquals(resultMap.get("the"), Integer.valueOf(8));
  }