blob: d9800a6eac2fcf715acd3b7b346097d100428c87 [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 Kruglikovb5a41e52016-06-23 15:37:41 -070021import org.junit.AfterClass;
22import org.junit.BeforeClass;
Aaron Kruglikov43d843d2016-07-01 06:39:38 -070023import org.junit.Ignore;
Aaron Kruglikovc0c27c02016-06-07 16:05:00 -070024import org.junit.Test;
Madan Jampani5e5b3d62016-02-01 16:03:33 -080025
Aaron Kruglikovc0c27c02016-06-07 16:05:00 -070026import static org.junit.Assert.assertEquals;
27import static org.junit.Assert.assertFalse;
28import static org.junit.Assert.assertTrue;
29
30/**git s
Madan Jampani5e5b3d62016-02-01 16:03:33 -080031 * Unit tests for {@link AtomixCounter}.
32 */
Aaron Kruglikov43d843d2016-07-01 06:39:38 -070033@Ignore
Madan Jampani5e5b3d62016-02-01 16:03:33 -080034public class AtomixLongTest extends AtomixTestBase {
35
Aaron Kruglikovb5a41e52016-06-23 15:37:41 -070036 @BeforeClass
37 public static void preTestSetup() throws Throwable {
38 createCopycatServers(3);
39 }
40
41 @AfterClass
42 public static void postTestCleanup() throws Exception {
43 clearTests();
44 }
45
Madan Jampani5e5b3d62016-02-01 16:03:33 -080046 @Override
47 protected ResourceType resourceType() {
48 return new ResourceType(DistributedLong.class);
49 }
50
51 @Test
52 public void testBasicOperations() throws Throwable {
Madan Jampani5e5b3d62016-02-01 16:03:33 -080053 basicOperationsTest(3);
Madan Jampani5e5b3d62016-02-01 16:03:33 -080054 }
55
56 protected void basicOperationsTest(int clusterSize) throws Throwable {
Madan Jampani5e5b3d62016-02-01 16:03:33 -080057 Atomix atomix = createAtomixClient();
Aaron Kruglikovb5a41e52016-06-23 15:37:41 -070058 AtomixCounter along = new AtomixCounter("test-long-basic-operations",
59 atomix.getLong("test-long").join());
Madan Jampani5e5b3d62016-02-01 16:03:33 -080060 assertEquals(0, along.get().join().longValue());
61 assertEquals(1, along.incrementAndGet().join().longValue());
62 along.set(100).join();
63 assertEquals(100, along.get().join().longValue());
64 assertEquals(100, along.getAndAdd(10).join().longValue());
65 assertEquals(110, along.get().join().longValue());
66 assertFalse(along.compareAndSet(109, 111).join());
67 assertTrue(along.compareAndSet(110, 111).join());
68 assertEquals(100, along.addAndGet(-11).join().longValue());
69 assertEquals(100, along.getAndIncrement().join().longValue());
70 assertEquals(101, along.get().join().longValue());
71 }
72}