Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.store.primitives.resources.impl; |
| 17 | |
| 18 | import static org.junit.Assert.*; |
| 19 | |
Madan Jampani | 07b5448 | 2016-03-09 10:34:18 -0800 | [diff] [blame] | 20 | import org.junit.Ignore; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 21 | import org.junit.Test; |
| 22 | |
| 23 | import io.atomix.Atomix; |
| 24 | import io.atomix.resource.ResourceType; |
| 25 | import io.atomix.variables.DistributedLong; |
| 26 | |
| 27 | /** |
| 28 | * Unit tests for {@link AtomixCounter}. |
| 29 | */ |
Madan Jampani | 07b5448 | 2016-03-09 10:34:18 -0800 | [diff] [blame] | 30 | @Ignore |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 31 | public class AtomixLongTest extends AtomixTestBase { |
| 32 | |
| 33 | @Override |
| 34 | protected ResourceType resourceType() { |
| 35 | return new ResourceType(DistributedLong.class); |
| 36 | } |
| 37 | |
| 38 | @Test |
| 39 | public void testBasicOperations() throws Throwable { |
| 40 | basicOperationsTest(1); |
| 41 | clearTests(); |
| 42 | basicOperationsTest(2); |
| 43 | clearTests(); |
| 44 | basicOperationsTest(3); |
| 45 | clearTests(); |
| 46 | } |
| 47 | |
| 48 | protected void basicOperationsTest(int clusterSize) throws Throwable { |
| 49 | createCopycatServers(clusterSize); |
| 50 | Atomix atomix = createAtomixClient(); |
| 51 | AtomixCounter along = new AtomixCounter("test-long", atomix.getLong("test-long").join()); |
| 52 | assertEquals(0, along.get().join().longValue()); |
| 53 | assertEquals(1, along.incrementAndGet().join().longValue()); |
| 54 | along.set(100).join(); |
| 55 | assertEquals(100, along.get().join().longValue()); |
| 56 | assertEquals(100, along.getAndAdd(10).join().longValue()); |
| 57 | assertEquals(110, along.get().join().longValue()); |
| 58 | assertFalse(along.compareAndSet(109, 111).join()); |
| 59 | assertTrue(along.compareAndSet(110, 111).join()); |
| 60 | assertEquals(100, along.addAndGet(-11).join().longValue()); |
| 61 | assertEquals(100, along.getAndIncrement().join().longValue()); |
| 62 | assertEquals(101, along.get().join().longValue()); |
| 63 | } |
| 64 | } |