Package com.hp.mwtests.ts.txoj.common.resources

Examples of com.hp.mwtests.ts.txoj.common.resources.AtomicObject


public class AtomicTest extends Test
{

public void run(String[] args)
    {
  AtomicObject foo = new AtomicObject();
  Uid u = foo.get_uid();
  int v;

  AtomicAction A = new AtomicAction();

  try
  {
      A.begin();

      logInformation("current object value is "+foo.get());

      foo.set(2);

      logInformation("object value is now "+foo.get());

      A.commit();

      int finalVal = foo.get();

      logInformation("final object value is now "+finalVal);

      if (finalVal == 2)
    logInformation("This is correct.");
      else
      {
    logInformation("This is incorrect.");
    assertFailure();
      }

      logInformation("\nStarting new action.");

      foo = new AtomicObject(u);

      A = new AtomicAction();

      A.begin();

      logInformation("current object value is "+foo.get());

      foo.set(4);

      A.commit();

      finalVal = foo.get();

      logInformation("final object value is "+finalVal);

      if (finalVal == 4)
    logInformation("This is correct.");
View Full Code Here


public class Hammer extends Test
{

public void run(String[] args)
    {
  HammerThreadedObject.object = new AtomicObject();
  HammerThreadedObject object1 = new HammerThreadedObject(2);
  HammerThreadedObject object2 = new HammerThreadedObject(-2);

  object1.start();
  object2.start();
View Full Code Here

public class BasicActionTest extends Test
{

public void run(String[] args)
    {
  AtomicObject foo = null;
  Uid u = null;

  for (int i = 0; i < args.length; i++)
  {
      if (args[i].compareTo("-uid") == 0)
      {
    u = new Uid(args[i+1]);

    if (!u.valid())
    {
        System.out.println("Invalid uid.");
        System.exit(1);
    }
      }
      if (args[i].compareTo("-help") == 0)
      {
    System.out.println("Usage: [-uid <uid>] [-help]");
    assertFailure();
      }
  }

  if (u == null)
      foo = new AtomicObject();
  else
      foo = new AtomicObject(u);

  AtomicAction A = new AtomicAction();

  try
  {
      A.begin();

      try
      {
    logInformation("current object value is "+foo.get());
      }
      catch (Exception e)
      {
      }

      try
      {
    logInformation("setting value");

    foo.set(foo.get()+2);
      }
      catch (Exception e)
      {
      }

      try
      {
    logInformation("object value is now "+foo.get());
      }
      catch (Exception e)
      {
      }

      A.commit();

      try
      {
    logInformation("final object value is now "+foo.get());
      }
      catch (Exception e)
      {
      }
  }
  catch (Exception e)
  {
      logInformation("AtomicObject exception raised.");
      A.abort();
  }

  logInformation("\nWill now try some erroneous conditions.\n");

  try
  {
      AtomicAction B = new AtomicAction();

      u = new Uid();
      foo = new AtomicObject(u);

      B.begin();

      try
      {
    logInformation("attempting to get value from non-existent object: "+foo.get());
      }
      catch (Exception e)
      {
      }

      logInformation("trying to set value to 5");

      try
      {
    foo.set(5);
      }
      catch (Exception e)
      {
      }

      try
      {
    logInformation("attempting to get value again: "+foo.get());
      }
      catch (Exception e)
      {
      }
View Full Code Here

    public static final int EXPECTED_RESULT = START_VALUE_1 + START_VALUE_2;

public void run(String[] args)
    {
  rand = new Random();
  atomicObject1 = new AtomicObject();
  atomicObject2 = new AtomicObject();

  System.out.println(atomicObject1.get_uid());
  System.out.println(atomicObject2.get_uid());

  try
View Full Code Here


public void run(String[] args)
    {
  rand = new Random();
  atomicObject1 = new AtomicObject();
  atomicObject2 = new AtomicObject();

  System.out.println(atomicObject1.get_uid());
  System.out.println(atomicObject2.get_uid());

  try
View Full Code Here

public void run(String[] args)
    {
  rand = new Random();

  atomicObject1 = new AtomicObject();
  atomicObject2 = new AtomicObject();

  System.out.println(atomicObject1.get_uid());
  System.out.println(atomicObject2.get_uid());

  try
View Full Code Here

public class ConcurrencyTest extends Test
{
   
public void run(String[] args)
    {
  AtomicObject foo = null;
  Uid u = null;
 
  for (int i = 0; i < args.length; i++)
  {
      if (args[i].compareTo("-uid") == 0)
      {
    u = new Uid(args[i+1]);

    if (!u.valid())
    {
        logInformation("Invalid uid.");
        assertFailure();
    }
      }
      if (args[i].compareTo("-help") == 0)
      {
    System.out.println("Usage: [-uid <uid>] [-help]");
    assertFailure();
      }
  }

  if (u == null)
      foo = new AtomicObject();
  else
      foo = new AtomicObject(u);

  logInformation("Starting top-level action.");

  AtomicAction A = new AtomicAction();

  try
  {
      A.begin();

      logInformation("Current atomic object state: " + foo.get());
 
      foo.set(7);

      if (u == null)
      {
    logInformation("Now waiting for 20 seconds.");
View Full Code Here

public class AtomicTest extends Test
{
   
public void run(String[] args)
    {
  AtomicObject foo = new AtomicObject();
  Uid u = foo.get_uid();
  int v;
 
  AtomicAction A = new AtomicAction();

  try
  {
      A.begin();
     
      logInformation("current object value is "+foo.get());
     
      foo.set(2);

      logInformation("object value is now "+foo.get());

      A.commit();

      int finalVal = foo.get();
     
      logInformation("final object value is now "+finalVal);

      if (finalVal == 2)
    logInformation("This is correct.");
      else
      {
    logInformation("This is incorrect.");
    assertFailure();
      }

      logInformation("\nStarting new action.");
 
      foo = new AtomicObject(u);
 
      A = new AtomicAction();
 
      A.begin();

      logInformation("current object value is "+foo.get());
 
      foo.set(4);

      A.commit();

      finalVal = foo.get();
     
      logInformation("final object value is "+finalVal);

      if (finalVal == 4)
    logInformation("This is correct.");
View Full Code Here

public class DestroyTest extends Test
{

public void run(String[] args)
    {
  AtomicObject atomicObject = new AtomicObject();
  Uid u = atomicObject.get_uid();
  AtomicAction a = new AtomicAction();
 
  a.begin();
 
  try
  {
      atomicObject.set(10);
  }
  catch (TestException e)
  {
      logInformation("set : failed");
            logInformation("Unexpected exception - "+e);
            e.printStackTrace(System.err);
      assertFailure();
  }
 
  logInformation("set : ok");

  if (!atomicObject.destroy())
  {
      logInformation("destroy : failed");

      a.abort();
     
      assertFailure();
  }

  a.commit();
 
  atomicObject = new AtomicObject(u);
 
  boolean passed = false;

  try
  {
      int val = atomicObject.get();
     
      if (val != -1)
      {
    logInformation("got : "+val);
View Full Code Here

public class BasicActionTest extends Test
{
   
public void run(String[] args)
    {
  AtomicObject foo = null;
  Uid u = null;
 
  for (int i = 0; i < args.length; i++)
  {
      if (args[i].compareTo("-uid") == 0)
      {
    u = new Uid(args[i+1]);

    if (!u.valid())
    {
        System.out.println("Invalid uid.");
        System.exit(1);
    }
      }
      if (args[i].compareTo("-help") == 0)
      {
    System.out.println("Usage: [-uid <uid>] [-help]");
    assertFailure();
      }
  }

  if (u == null)
      foo = new AtomicObject();
  else
      foo = new AtomicObject(u);

  AtomicAction A = new AtomicAction();

  try
  {
      A.begin();
 
      try
      {
    logInformation("current object value is "+foo.get());
      }
      catch (Exception e)
      {
      }

      try
      {
    logInformation("setting value");
   
    foo.set(foo.get()+2);
      }
      catch (Exception e)
      {
      }

      try
      {
    logInformation("object value is now "+foo.get());
      }
      catch (Exception e)
      {
      }

      A.commit();

      try
      {
    logInformation("final object value is now "+foo.get());
      }
      catch (Exception e)
      {
      }
  }
  catch (Exception e)
  {
      logInformation("AtomicObject exception raised.");
      A.abort();
  }

  logInformation("\nWill now try some erroneous conditions.\n");

  try
  {
      AtomicAction B = new AtomicAction();
     
      u = new Uid();
      foo = new AtomicObject(u);
     
      B.begin();

      try
      {
    logInformation("attempting to get value from non-existent object: "+foo.get());
      }
      catch (Exception e)
      {
      }
     
      logInformation("trying to set value to 5");

      try
      {
    foo.set(5);
      }
      catch (Exception e)
      {
      }

      try
      {
    logInformation("attempting to get value again: "+foo.get());
      }
      catch (Exception e)
      {
      }
View Full Code Here

TOP

Related Classes of com.hp.mwtests.ts.txoj.common.resources.AtomicObject

Copyright © 2018 www.massapicom. 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.