blob: c24cc7d3b7134207fb209a0ea71c760eb100abda [file] [log] [blame]
Madan Jampani5e5b3d62016-02-01 16:03:33 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Madan Jampani5e5b3d62016-02-01 16:03:33 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.primitives.resources.impl;
17
Madan Jampani5e5b3d62016-02-01 16:03:33 -080018import io.atomix.Atomix;
19import io.atomix.resource.ResourceType;
20import io.atomix.variables.DistributedLong;
Aaron Kruglikov5bb38122016-06-22 12:07:23 -070021import org.junit.Ignore;
Aaron Kruglikovc0c27c02016-06-07 16:05:00 -070022import org.junit.Test;
Madan Jampani5e5b3d62016-02-01 16:03:33 -080023
Aaron Kruglikovc0c27c02016-06-07 16:05:00 -070024import static org.junit.Assert.assertEquals;
25import static org.junit.Assert.assertFalse;
26import static org.junit.Assert.assertTrue;
27
28/**git s
Madan Jampani5e5b3d62016-02-01 16:03:33 -080029 * Unit tests for {@link AtomixCounter}.
30 */
Aaron Kruglikov5bb38122016-06-22 12:07:23 -070031@Ignore
Madan Jampani5e5b3d62016-02-01 16:03:33 -080032public class AtomixLongTest extends AtomixTestBase {
33
34 @Override
35 protected ResourceType resourceType() {
36 return new ResourceType(DistributedLong.class);
37 }
38
39 @Test
40 public void testBasicOperations() throws Throwable {
Madan Jampani5e5b3d62016-02-01 16:03:33 -080041 basicOperationsTest(3);
Madan Jampani5e5b3d62016-02-01 16:03:33 -080042 }
43
44 protected void basicOperationsTest(int clusterSize) throws Throwable {
45 createCopycatServers(clusterSize);
46 Atomix atomix = createAtomixClient();
47 AtomixCounter along = new AtomixCounter("test-long", atomix.getLong("test-long").join());
48 assertEquals(0, along.get().join().longValue());
49 assertEquals(1, along.incrementAndGet().join().longValue());
50 along.set(100).join();
51 assertEquals(100, along.get().join().longValue());
52 assertEquals(100, along.getAndAdd(10).join().longValue());
53 assertEquals(110, along.get().join().longValue());
54 assertFalse(along.compareAndSet(109, 111).join());
55 assertTrue(along.compareAndSet(110, 111).join());
56 assertEquals(100, along.addAndGet(-11).join().longValue());
57 assertEquals(100, along.getAndIncrement().join().longValue());
58 assertEquals(101, along.get().join().longValue());
59 }
60}