Permalink
Browse files

Adds testbed test for queued methods

  • Loading branch information...
ZainabAlShowely committed Aug 31, 2018
1 parent 3f86748 commit 5b79f7472435f6cb35c3218bc8cba2991e7ac5db
@@ -46,7 +46,6 @@ public class Foo
//implementation
}
}
private class QueuedMethodThread implements Runnable
{
@@ -109,3 +108,30 @@ public class Foo
}
@Override
public void run ()
{
boolean status=false;
while (true)
{
QueuedMethodMessage qmm = methodQueue.getNext();
if(qmm == null) return;
switch(qmm.type)
{
case method1_M:
_method1();
break;
default:
}
}
}
public void putCallTo(QueuedMethodMessage message)
{
methodQueue.put(message);
}
public void delete()
{
methodRemoval.interrupt();
}
}
}
@@ -16,4 +16,5 @@ use TestHarnessAssociation0_1_mMultiplicity.ump;
use TestHarnessCompositionsLeft.ump;
use TestHarnessCompositionsRight.ump;
use TestHarnessAssociationSpecializations.ump;
use TestHarnessQueuedMethod.ump;
@@ -0,0 +1,25 @@
namespace cruise.queued.method.test;
class QueuedAndNonQueuedMethods
{
String[] log;
queued queuedMethod()
{
try
{
Thread.sleep(500);
addLog("queuedMethod executed");
}
catch(Exception e) {addLog("queuedMethod interrupted");}
}
void nonqueuedMethod()
{
try
{
Thread.sleep(100);
addLog("nonqueuedMethod executed");
}
catch(Exception e) {addLog("nonqueuedMethod interrupted");}
}
}
@@ -0,0 +1,60 @@
package cruise.queued.method.test;
import org.junit.Assert;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import static org.junit.Assert.*;
public class QueuedMethodTest
{
QueuedAndNonQueuedMethods instance;
@Before
public void setUp()
{
instance = new QueuedAndNonQueuedMethods();
}
@After
public void tearDown()
{
instance.delete();
}
@Test
public void processQueuedAndNonQueuedMethods() throws InterruptedException
{
instance.queuedMethod();
instance.nonqueuedMethod();
Thread.sleep(1000); //Allows time for both methods to finish excecution
boolean queuedMethodExecuted = false;
boolean nonqueuedMethodExecuted = false;
for( String log : instance.getLog() )
{
if(queuedMethodExecuted && !nonqueuedMethodExecuted)
{
Assert.fail();
break;
}
switch (log)
{
case "queuedMethod executed":
queuedMethodExecuted = true;
case "nonQueuedMethod executed":
nonqueuedMethodExecuted = true;
}
if(log.contains("interrupted"))
{
Assert.fail();
}
}
}
}

0 comments on commit 5b79f74

Please sign in to comment.