Examples of RiakMap


Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

                if (coreResponse.hasContext())
                {
                    context = new Context(coreResponse.getContext());
                }

                RiakMap datatype = extractDatatype(element);

                return new Response(datatype, context);
            }

            @Override
View Full Code Here

Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

            new CoreFutureAdapter<Response, Location, DtUpdateOperation.Response, Location>(coreFuture)
            {
                @Override
                protected Response convertResponse(DtUpdateOperation.Response coreResponse)
                {
                    RiakMap map = null;
                    if (coreResponse.hasCrdtElement())
                    {
                        RiakDatatype element = coreResponse.getCrdtElement();
                        map = element.getAsMap();
                    }
View Full Code Here

Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

        Location loc = new Location(carts, updateResponse.getGeneratedKey());
    FetchMap fetch = new FetchMap.Builder(loc).build();
    FetchMap.Response fetchResponse = client.execute(fetch);

    // users
    RiakMap usersMap = fetchResponse.getDatatype();

    // username
    RiakMap usernameMap = usersMap.getMap(username);
    assertNotNull(usernameMap);

    // logins - counter
    RiakCounter numLoginsCounter = usernameMap.getCounter(numLogins);
    assertEquals((Long) 1L, numLoginsCounter.view());

    // last-login - register
    RiakRegister lastLoginTimeRegister = usernameMap.getRegister(lastLoginTime);

    assertTrue(Arrays.equals(now, lastLoginTimeRegister.view().getValue()));


    // logged-in - flag
    RiakFlag loggedInFlag = usernameMap.getFlag(loggedIn);
    assertEquals((Boolean) true, loggedInFlag.view());

    // cart - asSet
    RiakSet shoppingCartSet = usernameMap.getSet(shoppingCart);
    Set<BinaryValue> setView = shoppingCartSet.view();
    Set<BinaryValue> expectedSet = new HashSet<BinaryValue>();
    for (int i = 0; i < 10; ++i)
    {
      ByteBuffer b = ByteBuffer.allocate(4);
View Full Code Here

Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

    @Before
    @SuppressWarnings("unchecked")
    public void init() throws Exception
    {
        MockitoAnnotations.initMocks(this);
        when(mockResponse.getCrdtElement()).thenReturn(new RiakMap(new ArrayList<RiakMap.MapEntry>()));
        when(mockResponse.getContext()).thenReturn(BinaryValue.create(new byte[]{'1'}));
        when(mockFuture.get()).thenReturn(mockResponse);
        when(mockFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(mockResponse);
        when(mockFuture.isCancelled()).thenReturn(false);
        when(mockFuture.isDone()).thenReturn(true);
View Full Code Here

Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

    @Before
    @SuppressWarnings("unchecked")
    public void init() throws Exception
    {
        MockitoAnnotations.initMocks(this);
        when(mockResponse.getCrdtElement()).thenReturn(new RiakMap(new ArrayList<RiakMap.MapEntry>()));
        when(mockResponse.getContext()).thenReturn(BinaryValue.create(new byte[]{'1'}));
        when(mockFuture.get()).thenReturn(mockResponse);
        when(mockFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(mockResponse);
        when(mockFuture.isCancelled()).thenReturn(false);
        when(mockFuture.isDone()).thenReturn(true);
View Full Code Here

Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

        RiakDatatype element = converter.convert(resp);

        assertTrue(element.isMap());

        RiakMap crdtMap = element.getAsMap();

        assertTrue(crdtMap.get(counterKey).get(0).isCounter());
        assertTrue(crdtMap.get(setKey).get(0).isSet());
        assertTrue(crdtMap.get(mapKey).get(0).isMap());
        assertTrue(crdtMap.get(registerKey).get(0).isRegister());
        assertTrue(crdtMap.get(flagKey).get(0).isFlag());

        RiakCounter riakCounter = crdtMap.get(counterKey).get(0).getAsCounter();
        assertEquals((Long) counterValue, riakCounter.view());

        RiakSet crdtSet = crdtMap.get(setKey).get(0).getAsSet();
        assertEquals(wrappedSetValues, crdtSet.view());

        // the asMap doesn't have any values

        RiakRegister crdtRegister = crdtMap.get(registerKey).get(0).getAsRegister();
        assertEquals(registerValue, crdtRegister.getValue());

        RiakFlag crdtFlag = crdtMap.get(flagKey).get(0).getAsFlag();
        assertEquals(flagValue, crdtFlag.getEnabled());
    }
View Full Code Here

Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

        CrdtResponseConverter converter = new CrdtResponseConverter();

        RiakDatatype element = converter.convert(resp);

        assertTrue(element.isMap());
        RiakMap map = element.getAsMap();
        assertTrue(map.get(mapKey).get(0).isMap());
        map = map.get(mapKey).get(0).getAsMap();
        assertTrue(map.get(mapKey).get(0).isMap());
        map = map.get(mapKey).get(0).getAsMap();
        assertTrue(map.get(mapKey).get(0).isMap());


    }
View Full Code Here

Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

        BinaryValue key = BinaryValue.create("key");

        resetAndEmptyBucket(new Namespace(mapBucketType, bucketName));

        RiakMap map = fetchMap(mapBucketType, bucketName, key);

        assertTrue(map.view().isEmpty());

        Location location = new Location(new Namespace(mapBucketType, bucketName), key);
        BinaryValue setValue = BinaryValue.create("value");
        BinaryValue mapKey = BinaryValue.create("set");
       
        DtUpdateOperation update =
            new DtUpdateOperation.Builder(location)
                .withOp(new MapOp().update(mapKey, new SetOp().add(setValue)))
                .build();

        cluster.execute(update);
        update.get();

        map = fetchMap(mapBucketType, bucketName, key);
        assertEquals(1, map.view().size());
      assertNotNull(map.view().get(mapKey));
      assertEquals(1, map.view().get(mapKey).size());
        assertTrue(map.view().get(mapKey).get(0).isSet());
        RiakSet set = map.view().get(mapKey).get(0).getAsSet();
        assertTrue(set.view().contains(setValue));


        mapKey = BinaryValue.create("counter");
       
        update = new DtUpdateOperation.Builder(location)
            .withOp(new MapOp().update(mapKey, new CounterOp(1)))
            .build();

        cluster.execute(update);
        update.get();

        map = fetchMap(mapBucketType, bucketName, key);
        assertEquals(2, map.view().size());
      assertNotNull(map.view().get(mapKey));
      assertEquals(1, map.view().get(mapKey).size());
        assertTrue(map.view().get(mapKey).get(0).isCounter());
        RiakCounter counter = map.view().get(mapKey).get(0).getAsCounter();
        assertEquals((Long) 1L, counter.view());


        mapKey = BinaryValue.create("flag");

        update =
            new DtUpdateOperation.Builder(location)
                .withOp(new MapOp().update(mapKey, new FlagOp(true)))
                .build();

        cluster.execute(update);
        update.get();

        map = fetchMap(mapBucketType, bucketName, key);
        assertEquals(3, map.view().size());
      assertNotNull(map.view().get(mapKey));
      assertEquals(1, map.view().get(mapKey).size());
        assertTrue(map.view().get(mapKey).get(0).isFlag());
        RiakFlag flag = map.view().get(mapKey).get(0).getAsFlag();
        assertTrue(flag.getEnabled());


        mapKey = BinaryValue.create("register");
       
        update = new DtUpdateOperation.Builder(location)
            .withOp(new MapOp().update(mapKey, new RegisterOp(mapKey)))
            .build();

        cluster.execute(update);
        update.get();

        map = fetchMap(mapBucketType, bucketName, key);
        assertEquals(4, map.view().size());
      assertNotNull(map.view().get(mapKey));
      assertEquals(1, map.view().get(mapKey).size());
        RiakRegister register = map.view().get(mapKey).get(0).getAsRegister();
        assertEquals(mapKey, register.getValue());


        mapKey = BinaryValue.create("map");

        update = new DtUpdateOperation.Builder(location)
            .withOp(new MapOp().update(mapKey, new MapOp().update(mapKey, new FlagOp(false))))
            .build();

        cluster.execute(update);
        update.get();

        map = fetchMap(mapBucketType, bucketName, key);
        Map<BinaryValue, List<RiakDatatype>> mapView = map.view();
        assertEquals(5, mapView.size());

        assertTrue(mapView.containsKey(mapKey));
      assertNotNull(map.view().get(mapKey));
      assertEquals(1, map.view().get(mapKey).size());
        assertTrue(mapView.get(mapKey).get(0).isMap());
        RiakMap nestedMap = mapView.get(mapKey).get(0).getAsMap();
        Map<BinaryValue, List<RiakDatatype>> nestedMapView = nestedMap.view();
        assertEquals(1, nestedMapView.size());

        assertTrue(nestedMapView.containsKey(mapKey));
      assertNotNull(map.view().get(mapKey));
      assertEquals(1, map.view().get(mapKey).size());
View Full Code Here

Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

        if (!update.isSuccess())
        {
            fail("Update operation failed: " + update.cause().toString());
        }
       
        RiakMap map;
        if (returnBody)
        {
            DtUpdateOperation.Response response = update.get();
            assertNotNull(response);
            assertTrue(response.hasCrdtElement());
            assertTrue(response.hasContext());
            RiakDatatype dt = response.getCrdtElement();
            assertTrue(dt.isMap());
            map = dt.getAsMap();
        }
        else
        {
            map = fetchMap(mapBucketType, bucketName, key);
        }
       
       
        map = map.getMap(username);
        assertNotNull(map);
        RiakCounter counter = map.getCounter(logins);
        assertNotNull(counter);
        RiakRegister register = map.getRegister(lastLogin);
        assertNotNull(register);
        RiakFlag flag = map.getFlag(loggedIn);
        assertNotNull(flag);
        RiakSet set = map.getSet(cartContents);
        assertNotNull(set);
       
        resetAndEmptyBucket(new Namespace(mapBucketType, bucketName));
       
    }
View Full Code Here

Examples of com.basho.riak.client.core.query.crdt.types.RiakMap

        assertNotNull(response);
        assertTrue(response.hasCrdtElement());
        assertTrue(response.hasContext());
        RiakDatatype dt = response.getCrdtElement();
        assertTrue(dt.isMap());
        RiakMap map = dt.getAsMap();
       
        resetAndEmptyBucket(new Namespace(mapBucketType, bucketName));
       
       
       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.