Skip to content

Commit

Permalink
Added new grading driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascraigschmidt committed May 17, 2014
1 parent 00abff2 commit e487ce8
Show file tree
Hide file tree
Showing 10 changed files with 800 additions and 21 deletions.
15 changes: 9 additions & 6 deletions assignments/week-1-assignment-0-v2/Assignment-Description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@ view will pop up in Eclipse and run the tests contained therein. All
tests should pass. The ArrayBlockingQueue will pass because your
testQueue method runs successfully. The tests for BuggyBlockingQueue
(which is an intentionally flawed class), should "pass" if some error
occurs while running testQueue (these errors are expected). As long
as these JUnit tests both "pass" successfully your program will be be
consider "correct" for the purposes of assessing this assignment.
occurs while running testQueue (these errors are expected). If a test
passes a green-check mark will appear next to the test in the JUnit
view. As long as this JUnit test "passes" successfully your program
will be be consider "correct" for the purposes of assessing this
assignment.

If the tests run and "pass," you should see check-marks next to each
of the tests in the JUnit view. If you set the diagnosticsEnabled
flag to true then debugging output will be printed to the console as
the tests run. This text is for informational purposes only and have
no bearing on whether your program is "correct," but will help you to
better understand what it's doing.
the tests run. This debugging output is for informational purposes
only and have no bearing on whether your program is "correct." If the
tests run and "pass," you should see a green check-mark next to the
test in the JUnit view, which is all that matters.
2 changes: 1 addition & 1 deletion assignments/week-1-assignment-0/Assignment-Description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ To run the JUnit tests in Eclipse, right-click on
SynchronizedQueueTest.java and go to "Run As > JUnit Test". The JUnit
view will pop up in Eclipse and run the test contained therein. If
your testQueue method runs successfully the ArrayBlockingQueue should
pass, i.e., a green-check mark will appear net to the test in the
pass, i.e., a green-check mark will appear next to the test in the
JUnit view. As long as this JUnit test "passes" successfully your
program will be be consider "correct" for the purposes of assessing
this assignment.
Expand Down
33 changes: 19 additions & 14 deletions assignments/week-2-assignment-1/Assignment-Description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Week 2: Programming Assignment 1
Released Monday, May 19th, 2014
Due Monday, June 2nd, 2014

In this seonc assignment, you will implement a subset of the
In this second assignment, you'll implement a subset of the
java.util.concurrent.atomic.SimpleAtomicLong class using a Java
ReentrantReadWriteLock. The goal is to understand how to use
ReentrantReadWriteLock to serialize access to a variable that's shared
by multiple threads.

The BuggyLongTest.java program shows what happens if concurrent access
to a long isn't properly serialized. This test program works best on
a multi-core/multi-processor machine, which should actually induce
failure due to race conditions stemming from parallel execution. If
this test "succeeds" then your target platform is not sufficiently
parallel to demonstrate the bug.
a multi-core/multi-processor machine, which should induce a failure
due to race conditions stemming from parallel execution. If this test
"succeeds" then your target platform may not be sufficiently parallel
to demonstrate the race conditions.

In the src/edu/vuum/mocca directory you'll find the
SimpleAtomicLong.java class, which contains the skeleton Java code
Expand Down Expand Up @@ -48,23 +48,28 @@ classes, which are described in this video:

Section 1: Module 2: Part 9: Java CountDownLatch

At the moment, all these videos are available in the YouTube playlist
at

https://www.youtube.com/playlist?list=PLZ9NgFYEMxp4tbiFYip6tDNIEBRUDyPQK

When the 2014 POSA MOOC officially starts these videos will be
available at
These videos are available at

https://class.coursera.org/posa-002/lecture

To test this code in Eclipse, right-click on
When you first open the project in Eclipse, you might see compile
errors if JUnit is not included in your build path. To fix these
errors, open SynchronizedQueueTest.java, hover over "org.junit," and
click "Fix project setup." Make sure "Add JUnit 4 library to the
build path" is selected and then click "OK." At this point, the
compile errors should disappear!

To run the JUnit tests in Eclipse, right-click on
SimpleAtomicLongTests.java and Run As > JUnit Test. The JUnit view
will pop up in Eclipse and run the the tests, which are divided into
two subsets: multi-threaded and single-threaded tests. The
single-threaded tests verify functionality of all methods within a
single thread, while the multi-threaded tests do the same in a
multi-threaded environment. All tests should run successfully.
multi-threaded environment. All tests should run successfully, i.e.,
a green-check mark will appear next to the test in the JUnit view. As
long as this JUnit test "passes" successfully your program will be be
consider "correct" for the purposes of assessing this assignment.




Expand Down
7 changes: 7 additions & 0 deletions grading-drivers/week-2-assignment-1/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions grading-drivers/week-2-assignment-1/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>W2-A1-SimpleAtomicLong-Grading</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
57 changes: 57 additions & 0 deletions grading-drivers/week-2-assignment-1/Assessment-Description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Week 2: Programming Assignment 1 Peer Assessment Description

Due Monday, June 9th, 2014

You will be asked to evaluate five other student's projects as well as
do a self assessment of your own project. If you do not assess the
work of others, then you will not pass this assignment.

As you do your evaluation, please keep an open mind and focus on the
positive. Our goal is not to find every way to deduct points over
small deviations from the requirements or for legitimate differences
in implementation styles, etc. Look for ways to give points when it's
clear that the submitter has given a good faith effort to do the
project, and when it's likely that they've succeeded.

Review the submitter's source code. Since you did your own project,
you know where the changes should be and you have a good idea of the
kind of method calls and work flows that should be in the submitter's
code. Remember that they may have done things differently than you
did. That's fine.

Next, get a copy of the grading driver files from

https://github.com/douglascraigschmidt/POSA-14/tree/master/grading-drivers/week-2-assignment-1

and copy the submitter's SimpleAtomicLong.java file into your IDE
(which may have been given a random, odd name by Coursera, so you'll
need to rename it) and store it in the src/edu/vuum/mocca/ directory.
I recommend scanning the submitted code to ensure there are no changes
other than adding the appropriate code as indicated by the "TODO"
comments. A quick way to check for this automatically is to run "diff"
on the original SimpleAtomicLong.java file and the submitted
SimpleAtomicLong.java file to make sure all the changes are as
expected, in the expected places in the code. Then make sure
everything compiles properly in your environment. Note that the
grading drivers are in a different location than the original
skeletons to ensure that all submissions are tested against the
"master" regression tests and minimize the amount of code that comes
from "the wild".

Once you've reviewed the code against the rubric described below
please try to run it, walking through the steps called out in the
grading video that we'll create in each week's "VIrtual Office Hours"
(see item #38 in the POSA MOOC FAQ at
http://www.coursera.org/course/posa for info on Virtual Office
Hours). I suggest you make a fresh Eclipse workspace when doing this,
so that the submitter's code is isolated and easily distinguishable
from yours. One way you can do that is to select File > Open Workspace
> Browse > New Folder. This will lead to a new, empty Eclipse
workspace. Then you can copy that submitter's SimpleAtomicLong.java
file into this new workspace. Also, it's recommended to run the
submitted code a virtual machine sandbox to further isolate it from
causing harm.

And again, remember that most everyone is working very hard and
putting in a serious effort. When in doubt, err on the side of giving
too many points, rather than giving too few.
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package edu.vuum.mocca;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
* @class BuggyLongTest
*
* @brief This class shows what happens if concurrent access to a long
* isn't properly serialized.
*/
class BuggyLongTest
{
/**
* Number of iterations to run the test.
*/
static final long mMaxIterations = 100000000;

/**
* Barrier synchronizer that controls when the two threads start
* running the test.
*/
static CyclicBarrier mStartBarrier = new CyclicBarrier(2);

/**
* Barrier synchronizer that controls when the main thread can
* return.
*/
static CountDownLatch mStopLatch = new CountDownLatch(2);

/**
* An instance of long that's not protected by a lock.
*/
static long mCounter = 0;

/**
* Main entry point method that runs the test.
*/
public static void main(String[] args) {
try {
System.out.println("Starting BuggyLongTest");

/**
* Start a Thread whose Runnable decrements the SimpleAtomicLong
* mMaxIterations number of times.
*/
new Thread(new Runnable()
{ public void run() {
try
{
/**
* Wait for both Threads to start running
* before beginning the loop.
*/
mStartBarrier.await();

for (int i = 0; i < mMaxIterations; ++i)
mCounter--;

/**
* Inform the main thread that we're done.
*/
mStopLatch.countDown();
}
catch (Exception e)
{
System.out.println("problem here");
}
}
}).start();

/**
* Start a Thread whose Runnable increments the SimpleAtomicLong
* mMaxIterations number of times.
*/
new Thread(new Runnable()
{ public void run() {
try {
/**
* Wait for both Threads to start running
* before beginning the loop.
*/
mStartBarrier.await();

for (int i = 0; i < mMaxIterations; ++i)
mCounter++;

/**
* Inform the main thread that we're done.
*/
mStopLatch.countDown();
}
catch (Exception e) { }
}
}).start();

/**
* Barrier synchronizer that waits for both worker threads
* to exit before continuing.
*/
mStopLatch.await();

long result = mCounter;
/**
* Check to ensure the test worked, i.e., mCounter's value
* should be 0.
*/
if (result == 0)
System.out.println("test worked");
else
System.out.println("test failed: mCounter = " + result);

System.out.println("Finishing BuggyLongTest");
}
catch (Exception e) { }
}
}
Loading

0 comments on commit e487ce8

Please sign in to comment.