Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.mapdb;/*
   * Written by Doug Lea with assistance from members of JCP JSR-166
   * Expert Group and released to the public domain, as explained at
   * Other contributors include Andrew Wright, Jeffrey Hayes, 
   * Pat Fisher, Mike Judd. 
 public class AtomicLongTest extends TestCase {
     DB db = DBMaker.newMemoryDB().transactionDisable().make();
     Atomic.Long ai = .createAtomicLong("test", 1);

constructor initializes to given value
     public void testConstructor(){

default constructed initializes to zero
     public void testConstructor2(){
         Atomic.Long ai = .getAtomicLong("test2");

get returns the last value set
     public void testGetSet(){

compareAndSet succeeds in changing value if equal to expected else fails
     public void testCompareAndSet(){
         assertFalse((7 == .get()));

compareAndSet in one thread enables another waiting for value to succeed
     public void testCompareAndSetInMultipleThreads() throws InterruptedException {
         Thread t = new Thread(new Runnable() {
             public void run() {
                 while(!.compareAndSet(2, 3)) Thread.yield();
             assertTrue(.compareAndSet(1, 2));
             assertEquals(.get(), 3);

getAndSet returns previous value and sets to given value
     public void testGetAndSet(){

getAndAdd returns previous value and adds given value
     public void testGetAndAdd(){

getAndDecrement returns previous value and decrements
     public void testGetAndDecrement(){

getAndIncrement returns previous value and increments
    public void testGetAndIncrement(){

addAndGet adds given value to current, and returns current value
    public void testAddAndGet(){

decrementAndGet decrements and returns current value
    public void testDecrementAndGet(){

incrementAndGet increments and returns current value
    public void testIncrementAndGet(){

toString returns current value.
    public void testToString() {
        for (long i = -12; i < 6; ++i) {
            assertEquals(.toString(), Long.toString(i));

longValue returns current value.
    public void testLongValue() {
        for (int i = -12; i < 6; ++i) {

floatValue returns current value.
    public void testFloatValue() {
        for (int i = -12; i < 6; ++i) {

doubleValue returns current value.
    public void testDoubleValue() {
        for (int i = -12; i < 6; ++i) {
New to GrepCode? Check out our FAQ X