From bc0b0fa14b18acaeaf6bf8f9bf0a032c212d2f76 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Wed, 31 Oct 2012 14:06:57 +0000
Subject: [PATCH 001/142] Initial Commit
---
deadlocks/pom.xml | 61 ++++++++++++
.../main/java/threads/deadlock/Account.java | 35 +++++++
.../threads/deadlock/AvoidsDeadlockDemo.java | 98 +++++++++++++++++++
.../java/threads/deadlock/DeadlockDemo.java | 88 +++++++++++++++++
.../threads/deadlock/OverdrawnException.java | 7 ++
5 files changed, 289 insertions(+)
create mode 100644 deadlocks/pom.xml
create mode 100644 deadlocks/src/main/java/threads/deadlock/Account.java
create mode 100644 deadlocks/src/main/java/threads/deadlock/AvoidsDeadlockDemo.java
create mode 100644 deadlocks/src/main/java/threads/deadlock/DeadlockDemo.java
create mode 100644 deadlocks/src/main/java/threads/deadlock/OverdrawnException.java
diff --git a/deadlocks/pom.xml b/deadlocks/pom.xml
new file mode 100644
index 0000000..49d9acd
--- /dev/null
+++ b/deadlocks/pom.xml
@@ -0,0 +1,61 @@
+
+
+ 4.0.0
+ com.captaindebug
+ deadlocks
+ jar
+ 1.0-SNAPSHOT
+ Example Deadlock code
+
+ 1.6.1
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4jVersion}
+
+
+
+ org.slf4j
+ slf4j-log4j12
+ ${slf4jVersion}
+ runtime
+
+
+ log4j
+ log4j
+ 1.2.16
+ runtime
+
+
+ junit
+ junit
+ 4.8.2
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.6
+
+
+
+
diff --git a/deadlocks/src/main/java/threads/deadlock/Account.java b/deadlocks/src/main/java/threads/deadlock/Account.java
new file mode 100644
index 0000000..d355915
--- /dev/null
+++ b/deadlocks/src/main/java/threads/deadlock/Account.java
@@ -0,0 +1,35 @@
+package threads.deadlock;
+
+public class Account {
+
+ private final int number;
+
+ private int balance;
+
+ public Account(int number, int openingBalance) {
+ this.number = number;
+ this.balance = openingBalance;
+ }
+
+ public void withDrawAmount(int amount) throws OverdrawnException {
+
+ if (amount > balance) {
+ throw new OverdrawnException();
+ }
+
+ balance -= amount;
+ }
+
+ public void deposit(int amount) {
+
+ balance += amount;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public int getBalance() {
+ return balance;
+ }
+}
diff --git a/deadlocks/src/main/java/threads/deadlock/AvoidsDeadlockDemo.java b/deadlocks/src/main/java/threads/deadlock/AvoidsDeadlockDemo.java
new file mode 100644
index 0000000..5f6942d
--- /dev/null
+++ b/deadlocks/src/main/java/threads/deadlock/AvoidsDeadlockDemo.java
@@ -0,0 +1,98 @@
+package threads.deadlock;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+public class AvoidsDeadlockDemo {
+
+ private static final int NUM_ACCOUNTS = 10;
+ private static final int NUM_THREADS = 20;
+ private static final int NUM_ITERATIONS = 100000;
+
+ static final Random rnd = new Random();
+
+ List accounts = new ArrayList();
+
+ public static void main(String args[]) {
+
+ AvoidsDeadlockDemo demo = new AvoidsDeadlockDemo();
+ demo.setUp();
+ demo.run();
+ }
+
+ void setUp() {
+
+ for (int i = 0; i < NUM_ACCOUNTS; i++) {
+ Account account = new Account(i, rnd.nextInt(1000));
+ accounts.add(account);
+ }
+ }
+
+ void run() {
+
+ for (int i = 0; i < NUM_THREADS; i++) {
+ new BadTransferOperation(i).start();
+ }
+ }
+
+ class BadTransferOperation extends Thread {
+
+ int threadNum;
+
+ BadTransferOperation(int threadNum) {
+ this.threadNum = threadNum;
+ }
+
+ @Override
+ public void run() {
+
+ for (int i = 0; i < NUM_ITERATIONS; i++) {
+
+ Account toAccount = accounts.get(rnd.nextInt(NUM_ACCOUNTS));
+ Account fromAccount = accounts.get(rnd.nextInt(NUM_ACCOUNTS));
+ int amount = rnd.nextInt(1000);
+
+ if (!toAccount.equals(fromAccount)) {
+ try {
+ transfer(fromAccount, toAccount, amount);
+ System.out.print(".");
+ } catch (OverdrawnException e) {
+ System.out.print("-");
+ }
+
+ if (i % 60 == 0) {
+ System.out.print("\n");
+ }
+ }
+ }
+ System.out.println("Thread Complete: " + threadNum);
+ }
+
+ /**
+ * This is the crucial point here. The idea is that to avoid deadlock
+ * you need to ensure that threads can't try to lock the same two
+ * accounts in the same order
+ */
+ private void transfer(Account fromAccount, Account toAccount, int transferAmount) throws OverdrawnException {
+
+ if (fromAccount.getNumber() > toAccount.getNumber()) {
+
+ synchronized (fromAccount) {
+ synchronized (toAccount) {
+ fromAccount.withDrawAmount(transferAmount);
+ toAccount.deposit(transferAmount);
+ }
+ }
+ } else {
+
+ synchronized (toAccount) {
+ synchronized (fromAccount) {
+ fromAccount.withDrawAmount(transferAmount);
+ toAccount.deposit(transferAmount);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/deadlocks/src/main/java/threads/deadlock/DeadlockDemo.java b/deadlocks/src/main/java/threads/deadlock/DeadlockDemo.java
new file mode 100644
index 0000000..3a3a1c4
--- /dev/null
+++ b/deadlocks/src/main/java/threads/deadlock/DeadlockDemo.java
@@ -0,0 +1,88 @@
+package threads.deadlock;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+public class DeadlockDemo {
+
+ private static final int NUM_ACCOUNTS = 10;
+ private static final int NUM_THREADS = 20;
+ private static final int NUM_ITERATIONS = 100000;
+
+ static final Random rnd = new Random();
+
+ List accounts = new ArrayList();
+
+ public static void main(String args[]) {
+
+ DeadlockDemo demo = new DeadlockDemo();
+ demo.setUp();
+ demo.run();
+ }
+
+ void setUp() {
+
+ for (int i = 0; i < NUM_ACCOUNTS; i++) {
+ Account account = new Account(i, rnd.nextInt(1000));
+ accounts.add(account);
+ }
+ }
+
+ void run() {
+
+ for (int i = 0; i < NUM_THREADS; i++) {
+ new BadTransferOperation(i).start();
+ }
+ }
+
+ class BadTransferOperation extends Thread {
+
+ int threadNum;
+
+ BadTransferOperation(int threadNum) {
+ this.threadNum = threadNum;
+ }
+
+ @Override
+ public void run() {
+
+ for (int i = 0; i < NUM_ITERATIONS; i++) {
+
+ Account toAccount = accounts.get(rnd.nextInt(NUM_ACCOUNTS));
+ Account fromAccount = accounts.get(rnd.nextInt(NUM_ACCOUNTS));
+ int amount = rnd.nextInt(1000);
+
+ if (!toAccount.equals(fromAccount)) {
+ try {
+ transfer(fromAccount, toAccount, amount);
+ System.out.print(".");
+ } catch (OverdrawnException e) {
+ System.out.print("-");
+ }
+
+ if (i % 60 == 0) {
+ System.out.print("\n");
+ }
+ }
+ }
+ // This will never get to here...
+ System.out.println("Thread Complete: " + threadNum);
+ }
+
+ /**
+ * The clue to spotting deadlocks is in the nested locking -
+ * synchronized keywords. Note that the locks DON'T have to be next to
+ * each other to be nested.
+ */
+ private void transfer(Account fromAccount, Account toAccount, int transferAmount) throws OverdrawnException {
+
+ synchronized (fromAccount) {
+ synchronized (toAccount) {
+ fromAccount.withDrawAmount(transferAmount);
+ toAccount.deposit(transferAmount);
+ }
+ }
+ }
+ }
+}
diff --git a/deadlocks/src/main/java/threads/deadlock/OverdrawnException.java b/deadlocks/src/main/java/threads/deadlock/OverdrawnException.java
new file mode 100644
index 0000000..4fffa4e
--- /dev/null
+++ b/deadlocks/src/main/java/threads/deadlock/OverdrawnException.java
@@ -0,0 +1,7 @@
+package threads.deadlock;
+
+public class OverdrawnException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+}
From 8816c9d9096878d429fc556492f4ee5b2443a339 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Wed, 31 Oct 2012 14:44:34 +0000
Subject: [PATCH 002/142] Added Deadlock Project Updated build all project
Settings Renamed TellDontAsk to telldontask to avoid GIT problems in eclipse
---
address/.gitignore | 1 +
build-all/.gitignore | 2 ++
build-all/pom.xml | 2 ++
dependency-injection-factory/.gitignore | 4 ++++
exceptions/.gitignore | 4 ++++
facebook/.gitignore | 4 ++++
powermock-tips/.gitignore | 4 ++++
sim-map-exc-res/.gitignore | 4 ++++
social/.gitignore | 4 ++++
state-machine/.gitignore | 4 ++++
telldontask/.gitignore | 4 ++++
{TellDontAsk => telldontask}/pom.xml | 0
.../src/main/java/com/captaindebug/bridge/ShoppingCart.java | 0
.../src/main/java/com/captaindebug/payment/MasterCard.java | 0
.../src/main/java/com/captaindebug/payment/PaymentMethod.java | 0
.../src/main/java/com/captaindebug/payment/Visa.java | 0
.../java/com/captaindebug/strategy/SpringShoppingCart.java | 0
.../java/com/captaindebug/telldontask/HomeController.java | 0
.../src/main/java/com/captaindebug/telldontask/Item.java | 0
.../main/java/com/captaindebug/telldontask/ShoppingCart.java | 0
{TellDontAsk => telldontask}/src/main/resources/log4j.xml | 0
telldontask/src/main/webapp/META-INF/MANIFEST.MF | 3 +++
.../main/webapp/WEB-INF/spring/appServlet/servlet-context.xml | 0
.../src/main/webapp/WEB-INF/spring/root-context.xml | 0
.../src/main/webapp/WEB-INF/views/home.jsp | 0
{TellDontAsk => telldontask}/src/main/webapp/WEB-INF/web.xml | 0
.../test/java/com/captaindebug/bridge/ShoppingCartTest.java | 0
.../com/captaindebug/strategy/SpringShoppingCartTest.java | 0
.../java/com/captaindebug/telldontask/ShoppingCartTest.java | 0
{TellDontAsk => telldontask}/src/test/resources/log4j.xml | 0
xml-tips-blog/.gitignore | 4 ++++
xml-tips-jaxb/.gitignore | 4 ++++
xml-tips-xmlbeans/.gitignore | 4 ++++
33 files changed, 52 insertions(+)
create mode 100644 address/.gitignore
create mode 100644 build-all/.gitignore
create mode 100644 dependency-injection-factory/.gitignore
create mode 100644 exceptions/.gitignore
create mode 100644 facebook/.gitignore
create mode 100644 powermock-tips/.gitignore
create mode 100644 sim-map-exc-res/.gitignore
create mode 100644 social/.gitignore
create mode 100644 state-machine/.gitignore
create mode 100644 telldontask/.gitignore
rename {TellDontAsk => telldontask}/pom.xml (100%)
rename {TellDontAsk => telldontask}/src/main/java/com/captaindebug/bridge/ShoppingCart.java (100%)
rename {TellDontAsk => telldontask}/src/main/java/com/captaindebug/payment/MasterCard.java (100%)
rename {TellDontAsk => telldontask}/src/main/java/com/captaindebug/payment/PaymentMethod.java (100%)
rename {TellDontAsk => telldontask}/src/main/java/com/captaindebug/payment/Visa.java (100%)
rename {TellDontAsk => telldontask}/src/main/java/com/captaindebug/strategy/SpringShoppingCart.java (100%)
rename {TellDontAsk => telldontask}/src/main/java/com/captaindebug/telldontask/HomeController.java (100%)
rename {TellDontAsk => telldontask}/src/main/java/com/captaindebug/telldontask/Item.java (100%)
rename {TellDontAsk => telldontask}/src/main/java/com/captaindebug/telldontask/ShoppingCart.java (100%)
rename {TellDontAsk => telldontask}/src/main/resources/log4j.xml (100%)
create mode 100644 telldontask/src/main/webapp/META-INF/MANIFEST.MF
rename {TellDontAsk => telldontask}/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml (100%)
rename {TellDontAsk => telldontask}/src/main/webapp/WEB-INF/spring/root-context.xml (100%)
rename {TellDontAsk => telldontask}/src/main/webapp/WEB-INF/views/home.jsp (100%)
rename {TellDontAsk => telldontask}/src/main/webapp/WEB-INF/web.xml (100%)
rename {TellDontAsk => telldontask}/src/test/java/com/captaindebug/bridge/ShoppingCartTest.java (100%)
rename {TellDontAsk => telldontask}/src/test/java/com/captaindebug/strategy/SpringShoppingCartTest.java (100%)
rename {TellDontAsk => telldontask}/src/test/java/com/captaindebug/telldontask/ShoppingCartTest.java (100%)
rename {TellDontAsk => telldontask}/src/test/resources/log4j.xml (100%)
create mode 100644 xml-tips-blog/.gitignore
create mode 100644 xml-tips-jaxb/.gitignore
create mode 100644 xml-tips-xmlbeans/.gitignore
diff --git a/address/.gitignore b/address/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/address/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/build-all/.gitignore b/build-all/.gitignore
new file mode 100644
index 0000000..650751b
--- /dev/null
+++ b/build-all/.gitignore
@@ -0,0 +1,2 @@
+/.settings
+/.project
diff --git a/build-all/pom.xml b/build-all/pom.xml
index c108525..15b2b78 100644
--- a/build-all/pom.xml
+++ b/build-all/pom.xml
@@ -17,7 +17,9 @@
../exceptions../sim-map-exc-res../state-machine
+ ../telldontask../social../facebook
+ ../deadlocks
\ No newline at end of file
diff --git a/dependency-injection-factory/.gitignore b/dependency-injection-factory/.gitignore
new file mode 100644
index 0000000..9dff9cc
--- /dev/null
+++ b/dependency-injection-factory/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/target
+/.classpath
diff --git a/exceptions/.gitignore b/exceptions/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/exceptions/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/facebook/.gitignore b/facebook/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/facebook/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/powermock-tips/.gitignore b/powermock-tips/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/powermock-tips/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/sim-map-exc-res/.gitignore b/sim-map-exc-res/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/sim-map-exc-res/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/social/.gitignore b/social/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/social/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/state-machine/.gitignore b/state-machine/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/state-machine/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/telldontask/.gitignore b/telldontask/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/telldontask/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/TellDontAsk/pom.xml b/telldontask/pom.xml
similarity index 100%
rename from TellDontAsk/pom.xml
rename to telldontask/pom.xml
diff --git a/TellDontAsk/src/main/java/com/captaindebug/bridge/ShoppingCart.java b/telldontask/src/main/java/com/captaindebug/bridge/ShoppingCart.java
similarity index 100%
rename from TellDontAsk/src/main/java/com/captaindebug/bridge/ShoppingCart.java
rename to telldontask/src/main/java/com/captaindebug/bridge/ShoppingCart.java
diff --git a/TellDontAsk/src/main/java/com/captaindebug/payment/MasterCard.java b/telldontask/src/main/java/com/captaindebug/payment/MasterCard.java
similarity index 100%
rename from TellDontAsk/src/main/java/com/captaindebug/payment/MasterCard.java
rename to telldontask/src/main/java/com/captaindebug/payment/MasterCard.java
diff --git a/TellDontAsk/src/main/java/com/captaindebug/payment/PaymentMethod.java b/telldontask/src/main/java/com/captaindebug/payment/PaymentMethod.java
similarity index 100%
rename from TellDontAsk/src/main/java/com/captaindebug/payment/PaymentMethod.java
rename to telldontask/src/main/java/com/captaindebug/payment/PaymentMethod.java
diff --git a/TellDontAsk/src/main/java/com/captaindebug/payment/Visa.java b/telldontask/src/main/java/com/captaindebug/payment/Visa.java
similarity index 100%
rename from TellDontAsk/src/main/java/com/captaindebug/payment/Visa.java
rename to telldontask/src/main/java/com/captaindebug/payment/Visa.java
diff --git a/TellDontAsk/src/main/java/com/captaindebug/strategy/SpringShoppingCart.java b/telldontask/src/main/java/com/captaindebug/strategy/SpringShoppingCart.java
similarity index 100%
rename from TellDontAsk/src/main/java/com/captaindebug/strategy/SpringShoppingCart.java
rename to telldontask/src/main/java/com/captaindebug/strategy/SpringShoppingCart.java
diff --git a/TellDontAsk/src/main/java/com/captaindebug/telldontask/HomeController.java b/telldontask/src/main/java/com/captaindebug/telldontask/HomeController.java
similarity index 100%
rename from TellDontAsk/src/main/java/com/captaindebug/telldontask/HomeController.java
rename to telldontask/src/main/java/com/captaindebug/telldontask/HomeController.java
diff --git a/TellDontAsk/src/main/java/com/captaindebug/telldontask/Item.java b/telldontask/src/main/java/com/captaindebug/telldontask/Item.java
similarity index 100%
rename from TellDontAsk/src/main/java/com/captaindebug/telldontask/Item.java
rename to telldontask/src/main/java/com/captaindebug/telldontask/Item.java
diff --git a/TellDontAsk/src/main/java/com/captaindebug/telldontask/ShoppingCart.java b/telldontask/src/main/java/com/captaindebug/telldontask/ShoppingCart.java
similarity index 100%
rename from TellDontAsk/src/main/java/com/captaindebug/telldontask/ShoppingCart.java
rename to telldontask/src/main/java/com/captaindebug/telldontask/ShoppingCart.java
diff --git a/TellDontAsk/src/main/resources/log4j.xml b/telldontask/src/main/resources/log4j.xml
similarity index 100%
rename from TellDontAsk/src/main/resources/log4j.xml
rename to telldontask/src/main/resources/log4j.xml
diff --git a/telldontask/src/main/webapp/META-INF/MANIFEST.MF b/telldontask/src/main/webapp/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5e94951
--- /dev/null
+++ b/telldontask/src/main/webapp/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
diff --git a/TellDontAsk/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/telldontask/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
similarity index 100%
rename from TellDontAsk/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
rename to telldontask/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
diff --git a/TellDontAsk/src/main/webapp/WEB-INF/spring/root-context.xml b/telldontask/src/main/webapp/WEB-INF/spring/root-context.xml
similarity index 100%
rename from TellDontAsk/src/main/webapp/WEB-INF/spring/root-context.xml
rename to telldontask/src/main/webapp/WEB-INF/spring/root-context.xml
diff --git a/TellDontAsk/src/main/webapp/WEB-INF/views/home.jsp b/telldontask/src/main/webapp/WEB-INF/views/home.jsp
similarity index 100%
rename from TellDontAsk/src/main/webapp/WEB-INF/views/home.jsp
rename to telldontask/src/main/webapp/WEB-INF/views/home.jsp
diff --git a/TellDontAsk/src/main/webapp/WEB-INF/web.xml b/telldontask/src/main/webapp/WEB-INF/web.xml
similarity index 100%
rename from TellDontAsk/src/main/webapp/WEB-INF/web.xml
rename to telldontask/src/main/webapp/WEB-INF/web.xml
diff --git a/TellDontAsk/src/test/java/com/captaindebug/bridge/ShoppingCartTest.java b/telldontask/src/test/java/com/captaindebug/bridge/ShoppingCartTest.java
similarity index 100%
rename from TellDontAsk/src/test/java/com/captaindebug/bridge/ShoppingCartTest.java
rename to telldontask/src/test/java/com/captaindebug/bridge/ShoppingCartTest.java
diff --git a/TellDontAsk/src/test/java/com/captaindebug/strategy/SpringShoppingCartTest.java b/telldontask/src/test/java/com/captaindebug/strategy/SpringShoppingCartTest.java
similarity index 100%
rename from TellDontAsk/src/test/java/com/captaindebug/strategy/SpringShoppingCartTest.java
rename to telldontask/src/test/java/com/captaindebug/strategy/SpringShoppingCartTest.java
diff --git a/TellDontAsk/src/test/java/com/captaindebug/telldontask/ShoppingCartTest.java b/telldontask/src/test/java/com/captaindebug/telldontask/ShoppingCartTest.java
similarity index 100%
rename from TellDontAsk/src/test/java/com/captaindebug/telldontask/ShoppingCartTest.java
rename to telldontask/src/test/java/com/captaindebug/telldontask/ShoppingCartTest.java
diff --git a/TellDontAsk/src/test/resources/log4j.xml b/telldontask/src/test/resources/log4j.xml
similarity index 100%
rename from TellDontAsk/src/test/resources/log4j.xml
rename to telldontask/src/test/resources/log4j.xml
diff --git a/xml-tips-blog/.gitignore b/xml-tips-blog/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/xml-tips-blog/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/xml-tips-jaxb/.gitignore b/xml-tips-jaxb/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/xml-tips-jaxb/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/xml-tips-xmlbeans/.gitignore b/xml-tips-xmlbeans/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/xml-tips-xmlbeans/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
From 5d8ba1e99b49b31a2eba88b2cc34eb36fb9919c0 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Wed, 31 Oct 2012 14:48:26 +0000
Subject: [PATCH 003/142] Update README
---
README | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/README b/README
index 19e82d4..3418940 100644
--- a/README
+++ b/README
@@ -10,6 +10,12 @@ address - see: blogs on testing techniques:
http://www.captaindebug.com/p/blogs-on-testing-techniques.html
+deadlocks - see: the blogs on Investigating Deadlocks
+http://www.captaindebug.com/2012/10/investigating-deadlocks-part-1.html
+http://www.captaindebug.com/2012/10/investigating-deadlocks-part-2.html
+http://www.captaindebug.com/2012/10/investigating-deadlocks-part-3.html
+http://www.captaindebug.com/2012/10/investigating-deadlocks-part-4-fixing.html
+
dependency-injection-factory - covers blogs on the Dependency Injection:
From 39b05c0517420f88bd633a0640ba92856d9d0fb2 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sun, 4 Nov 2012 16:51:12 +0000
Subject: [PATCH 004/142] Added the tryLock(...) examples to the Deadlock
project.
---
address/.gitignore | 3 +++
1 file changed, 3 insertions(+)
diff --git a/address/.gitignore b/address/.gitignore
index ea8c4bf..c708c36 100644
--- a/address/.gitignore
+++ b/address/.gitignore
@@ -1 +1,4 @@
/target
+/.settings
+/.classpath
+/.project
From 7838f3d94e69ed66f515a64115dd5f56306d49e2 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sat, 10 Nov 2012 07:36:38 +0000
Subject: [PATCH 005/142] Added tryLock examples
---
deadlocks/.gitignore | 4 +
.../src/main/java/threads/lock/Account.java | 80 +++++++++++++
.../java/threads/lock/TimeoutTrylockDemo.java | 111 ++++++++++++++++++
.../main/java/threads/lock/TrylockDemo.java | 111 ++++++++++++++++++
.../test/java/threads/lock/AccountTest.java | 53 +++++++++
.../test/java/threads/lock/package-info.java | 10 ++
6 files changed, 369 insertions(+)
create mode 100644 deadlocks/.gitignore
create mode 100644 deadlocks/src/main/java/threads/lock/Account.java
create mode 100644 deadlocks/src/main/java/threads/lock/TimeoutTrylockDemo.java
create mode 100644 deadlocks/src/main/java/threads/lock/TrylockDemo.java
create mode 100644 deadlocks/src/test/java/threads/lock/AccountTest.java
create mode 100644 deadlocks/src/test/java/threads/lock/package-info.java
diff --git a/deadlocks/.gitignore b/deadlocks/.gitignore
new file mode 100644
index 0000000..c708c36
--- /dev/null
+++ b/deadlocks/.gitignore
@@ -0,0 +1,4 @@
+/target
+/.settings
+/.classpath
+/.project
diff --git a/deadlocks/src/main/java/threads/lock/Account.java b/deadlocks/src/main/java/threads/lock/Account.java
new file mode 100644
index 0000000..5d5244f
--- /dev/null
+++ b/deadlocks/src/main/java/threads/lock/Account.java
@@ -0,0 +1,80 @@
+package threads.lock;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import threads.deadlock.OverdrawnException;
+
+public class Account implements Lock {
+
+ private final int number;
+
+ private int balance;
+
+ private final ReentrantLock lock;
+
+ public Account(int number, int openingBalance) {
+ this.number = number;
+ this.balance = openingBalance;
+ this.lock = new ReentrantLock();
+ }
+
+ public void withDrawAmount(int amount) throws OverdrawnException {
+
+ if (amount > balance) {
+ throw new OverdrawnException();
+ }
+
+ balance -= amount;
+ }
+
+ public void deposit(int amount) {
+
+ balance += amount;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public int getBalance() {
+ return balance;
+ }
+
+ // ------- Lock interface implementation
+
+ @Override
+ public void lock() {
+ lock.lock();
+ }
+
+ @Override
+ public void lockInterruptibly() throws InterruptedException {
+ lock.lockInterruptibly();
+ }
+
+ @Override
+ public Condition newCondition() {
+ return lock.newCondition();
+ }
+
+ @Override
+ public boolean tryLock() {
+ return lock.tryLock();
+ }
+
+ @Override
+ public boolean tryLock(long arg0, TimeUnit arg1) throws InterruptedException {
+ return lock.tryLock(arg0, arg1);
+ }
+
+ @Override
+ public void unlock() {
+ if (lock.isHeldByCurrentThread()) {
+ lock.unlock();
+ }
+ }
+
+}
diff --git a/deadlocks/src/main/java/threads/lock/TimeoutTrylockDemo.java b/deadlocks/src/main/java/threads/lock/TimeoutTrylockDemo.java
new file mode 100644
index 0000000..2857a4b
--- /dev/null
+++ b/deadlocks/src/main/java/threads/lock/TimeoutTrylockDemo.java
@@ -0,0 +1,111 @@
+package threads.lock;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+
+import threads.deadlock.OverdrawnException;
+
+public class TimeoutTrylockDemo {
+
+ private static final int NUM_ACCOUNTS = 10;
+ private static final int NUM_THREADS = 20;
+ private static final int NUM_ITERATIONS = 100000;
+ private static final int LOCK_TIMEOUT = 1;
+
+ static final Random rnd = new Random();
+
+ List accounts = new ArrayList();
+
+ public static void main(String args[]) {
+
+ TimeoutTrylockDemo demo = new TimeoutTrylockDemo();
+ demo.setUp();
+ demo.run();
+ }
+
+ void setUp() {
+
+ for (int i = 0; i < NUM_ACCOUNTS; i++) {
+ Account account = new Account(i, 1000);
+ accounts.add(account);
+ }
+ }
+
+ void run() {
+
+ for (int i = 0; i < NUM_THREADS; i++) {
+ new BadTransferOperation(i).start();
+ }
+ }
+
+ class BadTransferOperation extends Thread {
+
+ int threadNum;
+
+ BadTransferOperation(int threadNum) {
+ this.threadNum = threadNum;
+ }
+
+ @Override
+ public void run() {
+
+ int transactionCount = 0;
+
+ for (int i = 0; i < NUM_ITERATIONS; i++) {
+
+ Account toAccount = accounts.get(rnd.nextInt(NUM_ACCOUNTS));
+ Account fromAccount = accounts.get(rnd.nextInt(NUM_ACCOUNTS));
+ int amount = rnd.nextInt(1000);
+
+ if (!toAccount.equals(fromAccount)) {
+
+ boolean successfulTransfer = false;
+
+ try {
+ successfulTransfer = transfer(fromAccount, toAccount, amount);
+
+ } catch (OverdrawnException e) {
+ successfulTransfer = true;
+ }
+
+ if (successfulTransfer) {
+ transactionCount++;
+ }
+
+ }
+ }
+
+ System.out.println("Thread Complete: " + threadNum + " Successfully made " + transactionCount + " out of "
+ + NUM_ITERATIONS);
+ }
+
+ private boolean transfer(Account fromAccount, Account toAccount, int transferAmount) throws OverdrawnException {
+
+ boolean success = false;
+
+ try {
+ if (fromAccount.tryLock(LOCK_TIMEOUT, TimeUnit.MILLISECONDS)) {
+ try {
+ if (toAccount.tryLock(LOCK_TIMEOUT, TimeUnit.MILLISECONDS)) {
+
+ success = true;
+ fromAccount.withDrawAmount(transferAmount);
+ toAccount.deposit(transferAmount);
+ }
+ } finally {
+ toAccount.unlock();
+ }
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } finally {
+ fromAccount.unlock();
+ }
+
+ return success;
+ }
+
+ }
+}
diff --git a/deadlocks/src/main/java/threads/lock/TrylockDemo.java b/deadlocks/src/main/java/threads/lock/TrylockDemo.java
new file mode 100644
index 0000000..f1b6399
--- /dev/null
+++ b/deadlocks/src/main/java/threads/lock/TrylockDemo.java
@@ -0,0 +1,111 @@
+package threads.lock;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import threads.deadlock.OverdrawnException;
+
+public class TrylockDemo {
+
+ private static final int NUM_ACCOUNTS = 10;
+ private static final int NUM_THREADS = 20;
+ private static final int NUM_ITERATIONS = 100000;
+ private static final int LOCK_ATTEMPTS = 10000;
+
+ static final Random rnd = new Random();
+
+ List accounts = new ArrayList();
+
+ public static void main(String args[]) {
+
+ TrylockDemo demo = new TrylockDemo();
+ demo.setUp();
+ demo.run();
+ }
+
+ void setUp() {
+
+ for (int i = 0; i < NUM_ACCOUNTS; i++) {
+ Account account = new Account(i, 1000);
+ accounts.add(account);
+ }
+ }
+
+ void run() {
+
+ for (int i = 0; i < NUM_THREADS; i++) {
+ new BadTransferOperation(i).start();
+ }
+ }
+
+ class BadTransferOperation extends Thread {
+
+ int threadNum;
+
+ BadTransferOperation(int threadNum) {
+ this.threadNum = threadNum;
+ }
+
+ @Override
+ public void run() {
+
+ int transactionCount = 0;
+
+ for (int i = 0; i < NUM_ITERATIONS; i++) {
+
+ Account toAccount = accounts.get(rnd.nextInt(NUM_ACCOUNTS));
+ Account fromAccount = accounts.get(rnd.nextInt(NUM_ACCOUNTS));
+ int amount = rnd.nextInt(1000);
+
+ if (!toAccount.equals(fromAccount)) {
+
+ boolean successfulTransfer = false;
+
+ try {
+ successfulTransfer = transfer(fromAccount, toAccount, amount);
+
+ } catch (OverdrawnException e) {
+ successfulTransfer = true;
+ }
+
+ if (successfulTransfer) {
+ transactionCount++;
+ }
+
+ }
+ }
+
+ System.out.println("Thread Complete: " + threadNum + " Successfully made " + transactionCount + " out of "
+ + NUM_ITERATIONS);
+ }
+
+ private boolean transfer(Account fromAccount, Account toAccount, int transferAmount) throws OverdrawnException {
+
+ boolean success = false;
+ for (int i = 0; i < LOCK_ATTEMPTS; i++) {
+
+ try {
+ if (fromAccount.tryLock()) {
+ try {
+ if (toAccount.tryLock()) {
+
+ success = true;
+ fromAccount.withDrawAmount(transferAmount);
+ toAccount.deposit(transferAmount);
+ break;
+ }
+ } finally {
+ toAccount.unlock();
+ }
+ }
+ } finally {
+ fromAccount.unlock();
+ }
+ }
+
+ return success;
+ }
+
+ }
+}
diff --git a/deadlocks/src/test/java/threads/lock/AccountTest.java b/deadlocks/src/test/java/threads/lock/AccountTest.java
new file mode 100644
index 0000000..19208e8
--- /dev/null
+++ b/deadlocks/src/test/java/threads/lock/AccountTest.java
@@ -0,0 +1,53 @@
+/**
+ *
+ */
+package threads.lock;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Roger
+ *
+ * Created 19:19:26 1 Nov 2012
+ *
+ */
+public class AccountTest {
+
+ private Account instance;
+
+ @Before
+ public void setUp() throws Exception {
+ instance = new Account(1, 100);
+ }
+
+ /**
+ * In using Lock / ReenterantLock implementation it's your responsibility to
+ * unlock at the end of use.
+ */
+ @After
+ public void tearDown() throws Exception {
+ instance.unlock();
+ }
+
+ @Test
+ public void testTryLockAndLock() {
+
+ assertTrue(instance.tryLock());
+ }
+
+ /**
+ * Will pass because it's the same thread
+ */
+ @Test
+ public void testTryLockAndRelockAndPass() {
+
+ instance.lock();
+
+ assertTrue(instance.tryLock());
+ }
+
+}
diff --git a/deadlocks/src/test/java/threads/lock/package-info.java b/deadlocks/src/test/java/threads/lock/package-info.java
new file mode 100644
index 0000000..5509fb0
--- /dev/null
+++ b/deadlocks/src/test/java/threads/lock/package-info.java
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+/**
+ * @author Roger
+ *
+ * Created 19:18:29 1 Nov 2012
+ *
+ */
+package threads.lock;
\ No newline at end of file
From 50e62d3c53202f91f6f19d71692a2a2d062c02fc Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sun, 25 Nov 2012 21:35:28 +0000
Subject: [PATCH 006/142] Initial Project Import
---
spring-security/tomcat-ssl/.gitignore | 4 +
spring-security/tomcat-ssl/pom.xml | 158 ++++++++++++++++++
.../captaindebug/security/HomeController.java | 39 +++++
.../tomcat-ssl/src/main/resources/log4j.xml | 41 +++++
.../spring/appServlet/servlet-context.xml | 28 ++++
.../webapp/WEB-INF/spring/root-context.xml | 8 +
.../src/main/webapp/WEB-INF/views/home.jsp | 14 ++
.../src/main/webapp/WEB-INF/web.xml | 33 ++++
.../tomcat-ssl/src/test/resources/log4j.xml | 41 +++++
9 files changed, 366 insertions(+)
create mode 100644 spring-security/tomcat-ssl/.gitignore
create mode 100644 spring-security/tomcat-ssl/pom.xml
create mode 100644 spring-security/tomcat-ssl/src/main/java/com/captaindebug/security/HomeController.java
create mode 100644 spring-security/tomcat-ssl/src/main/resources/log4j.xml
create mode 100644 spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
create mode 100644 spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/root-context.xml
create mode 100644 spring-security/tomcat-ssl/src/main/webapp/WEB-INF/views/home.jsp
create mode 100644 spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml
create mode 100644 spring-security/tomcat-ssl/src/test/resources/log4j.xml
diff --git a/spring-security/tomcat-ssl/.gitignore b/spring-security/tomcat-ssl/.gitignore
new file mode 100644
index 0000000..c708c36
--- /dev/null
+++ b/spring-security/tomcat-ssl/.gitignore
@@ -0,0 +1,4 @@
+/target
+/.settings
+/.classpath
+/.project
diff --git a/spring-security/tomcat-ssl/pom.xml b/spring-security/tomcat-ssl/pom.xml
new file mode 100644
index 0000000..777d4b5
--- /dev/null
+++ b/spring-security/tomcat-ssl/pom.xml
@@ -0,0 +1,158 @@
+
+
+ 4.0.0
+ com.captaindebug
+ security
+ tomcat-ssl
+ war
+ 1.0.0-BUILD-SNAPSHOT
+
+ 1.6
+ 3.1.0.RELEASE
+ 1.6.9
+ 1.5.10
+
+
+
+
+ org.springframework
+ spring-context
+ ${org.springframework-version}
+
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ org.springframework
+ spring-webmvc
+ ${org.springframework-version}
+
+
+
+
+ org.aspectj
+ aspectjrt
+ ${org.aspectj-version}
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${org.slf4j-version}
+
+
+ org.slf4j
+ jcl-over-slf4j
+ ${org.slf4j-version}
+ runtime
+
+
+ org.slf4j
+ slf4j-log4j12
+ ${org.slf4j-version}
+ runtime
+
+
+ log4j
+ log4j
+ 1.2.15
+
+
+ javax.mail
+ mail
+
+
+ javax.jms
+ jms
+
+
+ com.sun.jdmk
+ jmxtools
+
+
+ com.sun.jmx
+ jmxri
+
+
+ runtime
+
+
+
+
+ javax.inject
+ javax.inject
+ 1
+
+
+
+
+ javax.servlet
+ servlet-api
+ 2.5
+ provided
+
+
+ javax.servlet.jsp
+ jsp-api
+ 2.1
+ provided
+
+
+ javax.servlet
+ jstl
+ 1.2
+
+
+
+
+ junit
+ junit
+ 4.7
+ test
+
+
+
+
+
+ maven-eclipse-plugin
+ 2.9
+
+
+ org.springframework.ide.eclipse.core.springnature
+
+
+ org.springframework.ide.eclipse.core.springbuilder
+
+ true
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+ -Xlint:all
+ true
+ true
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.2.1
+
+ org.test.int1.Main
+
+
+
+
+
diff --git a/spring-security/tomcat-ssl/src/main/java/com/captaindebug/security/HomeController.java b/spring-security/tomcat-ssl/src/main/java/com/captaindebug/security/HomeController.java
new file mode 100644
index 0000000..317eba0
--- /dev/null
+++ b/spring-security/tomcat-ssl/src/main/java/com/captaindebug/security/HomeController.java
@@ -0,0 +1,39 @@
+package com.captaindebug.security;
+
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * Handles requests for the application home page.
+ */
+@Controller
+public class HomeController {
+
+ private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
+
+ /**
+ * Simply selects the home view to render by returning its name.
+ */
+ @RequestMapping(value = "/", method = RequestMethod.GET)
+ public String home(Locale locale, Model model) {
+ logger.info("Welcome home! the client locale is "+ locale.toString());
+
+ Date date = new Date();
+ DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
+
+ String formattedDate = dateFormat.format(date);
+
+ model.addAttribute("serverTime", formattedDate );
+
+ return "home";
+ }
+
+}
diff --git a/spring-security/tomcat-ssl/src/main/resources/log4j.xml b/spring-security/tomcat-ssl/src/main/resources/log4j.xml
new file mode 100644
index 0000000..0c4528a
--- /dev/null
+++ b/spring-security/tomcat-ssl/src/main/resources/log4j.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
new file mode 100644
index 0000000..52418e0
--- /dev/null
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/root-context.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/root-context.xml
new file mode 100644
index 0000000..c38cdff
--- /dev/null
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/views/home.jsp b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/views/home.jsp
new file mode 100644
index 0000000..4783383
--- /dev/null
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/views/home.jsp
@@ -0,0 +1,14 @@
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ page session="false" %>
+
+
+ Codestin Search App
+
+
+
+ Hello world!
+
+
+
The time on the server is ${serverTime}.
+
+
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..b6cc56c
--- /dev/null
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+ contextConfigLocation
+ /WEB-INF/spring/root-context.xml
+
+
+
+
+ org.springframework.web.context.ContextLoaderListener
+
+
+
+
+ appServlet
+ org.springframework.web.servlet.DispatcherServlet
+
+ contextConfigLocation
+ /WEB-INF/spring/appServlet/servlet-context.xml
+
+ 1
+
+
+
+ appServlet
+ /
+
+
+
diff --git a/spring-security/tomcat-ssl/src/test/resources/log4j.xml b/spring-security/tomcat-ssl/src/test/resources/log4j.xml
new file mode 100644
index 0000000..2c802f4
--- /dev/null
+++ b/spring-security/tomcat-ssl/src/test/resources/log4j.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 79049371cdadb352bde4baa48986256e4580e529 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Mon, 26 Nov 2012 22:37:10 +0000
Subject: [PATCH 007/142] Ensured that the app works using HTTPS
1) Added Spring Security Jars to POM
2) Created minimal application-security.xml
3) Added reference to application-security to web.xml
---
spring-security/tomcat-ssl/pom.xml | 108 ++++++++++--------
.../appServlet/application-security.xml | 19 +++
.../spring/appServlet/servlet-context.xml | 2 -
.../src/main/webapp/WEB-INF/web.xml | 4 +-
4 files changed, 85 insertions(+), 48 deletions(-)
create mode 100644 spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml
diff --git a/spring-security/tomcat-ssl/pom.xml b/spring-security/tomcat-ssl/pom.xml
index 777d4b5..539c950 100644
--- a/spring-security/tomcat-ssl/pom.xml
+++ b/spring-security/tomcat-ssl/pom.xml
@@ -10,6 +10,7 @@
1.63.1.0.RELEASE
+ 3.1.3.RELEASE1.6.91.5.10
@@ -24,7 +25,7 @@
commons-loggingcommons-logging
-
+
@@ -32,14 +33,14 @@
spring-webmvc${org.springframework-version}
-
+
org.aspectjaspectjrt${org.aspectj-version}
-
-
+
+
org.slf4j
@@ -89,7 +90,7 @@
javax.inject1
-
+
javax.servlet
@@ -108,51 +109,68 @@
jstl1.2
-
+
junitjunit4.7test
-
+
+
+
+
+ org.springframework.security
+ spring-security-core
+ ${org.springsecurity-version}
+
+
+ org.springframework.security
+ spring-security-web
+ ${org.springsecurity-version}
+
+
+ org.springframework.security
+ spring-security-config
+ ${org.springsecurity-version}
+
-
-
-
- maven-eclipse-plugin
- 2.9
-
-
- org.springframework.ide.eclipse.core.springnature
-
-
- org.springframework.ide.eclipse.core.springbuilder
-
- true
- true
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.3.2
-
- 1.6
- 1.6
- -Xlint:all
- true
- true
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.2.1
-
- org.test.int1.Main
-
-
-
-
+
+
+
+ maven-eclipse-plugin
+ 2.9
+
+
+ org.springframework.ide.eclipse.core.springnature
+
+
+ org.springframework.ide.eclipse.core.springbuilder
+
+ true
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+ -Xlint:all
+ true
+ true
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.2.1
+
+ org.test.int1.Main
+
+
+
+
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml
new file mode 100644
index 0000000..e4e71fa
--- /dev/null
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
index 52418e0..4ece2e7 100644
--- a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -23,6 +23,4 @@
-
-
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml
index b6cc56c..da18481 100644
--- a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml
@@ -6,7 +6,9 @@
contextConfigLocation
- /WEB-INF/spring/root-context.xml
+ /WEB-INF/spring/root-context.xml
+ /WEB-INF/spring/appServlet/application-security.xml
+
From ca2e33b6cce3224280818217ea7c03dbdd146ca7 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Wed, 28 Nov 2012 22:12:13 +0000
Subject: [PATCH 008/142] Git Fix to merge problem do git add -f git
commit
---
deadlocks/.gitignore | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 deadlocks/.gitignore
diff --git a/deadlocks/.gitignore b/deadlocks/.gitignore
new file mode 100644
index 0000000..32a66e2
--- /dev/null
+++ b/deadlocks/.gitignore
@@ -0,0 +1,5 @@
+/.project
+/.settings
+/target
+/.classpath
+/.gitignore
From cb4dc8da34e5f48e4f9991dd989b3da6624ce2ee Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sat, 8 Dec 2012 17:46:23 +0000
Subject: [PATCH 009/142] Updated web.xml and application-security.xml on the
tomcat-ssl app
---
.../appServlet/application-security.xml | 5 ++--
.../src/main/webapp/WEB-INF/web.xml | 30 ++++++++++++++++---
2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml
index e4e71fa..6a34d56 100644
--- a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml
@@ -7,11 +7,10 @@
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
-
-
+
+
-
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml
index da18481..996fc29 100644
--- a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/web.xml
@@ -3,14 +3,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
-
+
contextConfigLocation/WEB-INF/spring/root-context.xml
- /WEB-INF/spring/appServlet/application-security.xml
+ /WEB-INF/spring/appServlet/application-security.xml
-
+
org.springframework.web.context.ContextLoaderListener
@@ -26,10 +27,31 @@
1
-
+
appServlet/
+
+ springSecurityFilterChain
+ org.springframework.web.filter.DelegatingFilterProxy
+
+
+ springSecurityFilterChain
+ /*
+
+
+
+
From db58220aba505cd79e0db5e84cb2e6c1531ba9b7 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sun, 20 Jan 2013 19:21:38 +0000
Subject: [PATCH 010/142] Initial idea / draft for unit testing threads
---
build-all/pom.xml | 2 +
unit-testing-threads/pom.xml | 61 +++++++++++++++++++
.../threading/bad_example/ThreadWrapper.java | 51 ++++++++++++++++
.../threading/bad_example/package-info.java | 10 +++
.../threading/good_example/ThreadWrapper.java | 58 ++++++++++++++++++
.../threading/good_example/package-info.java | 10 +++
.../bad_example/ThreadWrapperTest.java | 22 +++++++
.../good_example/ThreadWrapperTest.java | 24 ++++++++
8 files changed, 238 insertions(+)
create mode 100644 unit-testing-threads/pom.xml
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/package-info.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/package-info.java
create mode 100644 unit-testing-threads/src/test/java/com/captaindebug/threading/bad_example/ThreadWrapperTest.java
create mode 100644 unit-testing-threads/src/test/java/com/captaindebug/threading/good_example/ThreadWrapperTest.java
diff --git a/build-all/pom.xml b/build-all/pom.xml
index 15b2b78..03b9032 100644
--- a/build-all/pom.xml
+++ b/build-all/pom.xml
@@ -21,5 +21,7 @@
../social../facebook../deadlocks
+ ../spring-security/tomcat-ssl
+ ../unit-testing-threads
\ No newline at end of file
diff --git a/unit-testing-threads/pom.xml b/unit-testing-threads/pom.xml
new file mode 100644
index 0000000..3ceb32a
--- /dev/null
+++ b/unit-testing-threads/pom.xml
@@ -0,0 +1,61 @@
+
+
+ 4.0.0
+ com.captaindebug
+ unit-testing-threads
+ jar
+ 1.0-SNAPSHOT
+ Example Thread Testing Code
+
+ 1.6.1
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4jVersion}
+
+
+
+ org.slf4j
+ slf4j-log4j12
+ ${slf4jVersion}
+ runtime
+
+
+ log4j
+ log4j
+ 1.2.16
+ runtime
+
+
+ junit
+ junit
+ 4.8.2
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.6
+
+
+
+
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java
new file mode 100644
index 0000000..fb739bb
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java
@@ -0,0 +1,51 @@
+/**
+ *
+ */
+package com.captaindebug.threading.bad_example;
+
+/**
+ * @author Roger
+ *
+ * Created 18:35:58 20 Jan 2013
+ *
+ */
+public class ThreadWrapper {
+
+ private boolean result;
+
+ /**
+ * Any old worker thread...
+ */
+ class MyThread extends Thread {
+
+ @Override
+ public void run() {
+
+ try {
+ System.out.println("Start of the thread");
+ Thread.sleep(4000);
+ result = true;
+ System.out.println("End of the thread method");
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Start the thread running so that it does some work.
+ */
+ public void doWork() {
+
+ Thread thread = new MyThread();
+ thread.start();
+ System.out.println("Off and running...");
+ }
+
+ /**
+ * Retrieve the result.
+ */
+ public boolean getResult() {
+ return result;
+ }
+}
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/package-info.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/package-info.java
new file mode 100644
index 0000000..f6ad961
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/package-info.java
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+/**
+ * @author Roger
+ *
+ * Created 17:54:34 20 Jan 2013
+ *
+ */
+package com.captaindebug.threading.bad_example;
\ No newline at end of file
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java
new file mode 100644
index 0000000..267a1c0
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java
@@ -0,0 +1,58 @@
+/**
+ *
+ */
+package com.captaindebug.threading.good_example;
+
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author Roger
+ *
+ * Created 18:35:58 20 Jan 2013
+ *
+ */
+public class ThreadWrapper {
+
+ private CountDownLatch latch;
+
+ private boolean result;
+
+ /**
+ * Any old worker thread...
+ */
+ class MyThread extends Thread {
+
+ @Override
+ public void run() {
+
+ try {
+ System.out.println("Start of the thread");
+ Thread.sleep(4000);
+ result = true;
+ System.out.println("End of the thread method");
+
+ latch.countDown();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Start the thread running so that it does some work.
+ */
+ public void doWork(CountDownLatch latch) {
+
+ this.latch = latch;
+ Thread thread = new MyThread();
+ thread.start();
+ System.out.println("Off and running...");
+ }
+
+ /**
+ * Retrieve the result.
+ */
+ public boolean getResult() {
+ return result;
+ }
+}
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/package-info.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/package-info.java
new file mode 100644
index 0000000..66e1b21
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/package-info.java
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+/**
+ * @author Roger
+ *
+ * Created 17:54:49 20 Jan 2013
+ *
+ */
+package com.captaindebug.threading.good_example;
\ No newline at end of file
diff --git a/unit-testing-threads/src/test/java/com/captaindebug/threading/bad_example/ThreadWrapperTest.java b/unit-testing-threads/src/test/java/com/captaindebug/threading/bad_example/ThreadWrapperTest.java
new file mode 100644
index 0000000..2a5c4ca
--- /dev/null
+++ b/unit-testing-threads/src/test/java/com/captaindebug/threading/bad_example/ThreadWrapperTest.java
@@ -0,0 +1,22 @@
+package com.captaindebug.threading.bad_example;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class ThreadWrapperTest {
+
+ @Test
+ public void testDoWork() throws InterruptedException {
+
+ ThreadWrapper instance = new ThreadWrapper();
+
+ instance.doWork();
+
+ Thread.sleep(10000);
+
+ boolean result = instance.getResult();
+ assertTrue(result);
+ }
+
+}
diff --git a/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example/ThreadWrapperTest.java b/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example/ThreadWrapperTest.java
new file mode 100644
index 0000000..9a7679d
--- /dev/null
+++ b/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example/ThreadWrapperTest.java
@@ -0,0 +1,24 @@
+package com.captaindebug.threading.good_example;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.Test;
+
+public class ThreadWrapperTest {
+
+ @Test
+ public void testDoWork() throws InterruptedException {
+
+ ThreadWrapper instance = new ThreadWrapper();
+
+ CountDownLatch latch = new CountDownLatch(1);
+
+ instance.doWork(latch);
+ latch.await();
+ boolean result = instance.getResult();
+ assertTrue(result);
+ }
+
+}
From d2e3166d6fc329b533a86481409b0d616657a22a Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Wed, 23 Jan 2013 22:24:04 +0000
Subject: [PATCH 011/142] Updated scenario under discussion.
---
.../threading/bad_example/ThreadWrapper.java | 44 ++++++++---------
.../threading/good_example/ThreadWrapper.java | 49 ++++++++-----------
.../bad_example/ThreadWrapperTest.java | 8 ++-
.../good_example/ThreadWrapperTest.java | 8 ++-
4 files changed, 54 insertions(+), 55 deletions(-)
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java
index fb739bb..21b6722 100644
--- a/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java
@@ -11,41 +11,37 @@
*/
public class ThreadWrapper {
- private boolean result;
-
/**
- * Any old worker thread...
+ * Start the thread running so that it does some work.
*/
- class MyThread extends Thread {
+ public void doWork() {
+
+ Thread thread = new Thread() {
- @Override
- public void run() {
+ /**
+ * Run method adding data to a fictitious database
+ */
+ @Override
+ public void run() {
- try {
System.out.println("Start of the thread");
- Thread.sleep(4000);
- result = true;
+ addDataToDB();
System.out.println("End of the thread method");
- } catch (InterruptedException e) {
- e.printStackTrace();
}
- }
- }
- /**
- * Start the thread running so that it does some work.
- */
- public void doWork() {
+ private void addDataToDB() {
+
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ };
- Thread thread = new MyThread();
thread.start();
System.out.println("Off and running...");
}
- /**
- * Retrieve the result.
- */
- public boolean getResult() {
- return result;
- }
}
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java
index 267a1c0..6cd21d6 100644
--- a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java
@@ -13,46 +13,37 @@
*/
public class ThreadWrapper {
- private CountDownLatch latch;
-
- private boolean result;
-
/**
- * Any old worker thread...
+ * Start the thread running so that it does some work.
*/
- class MyThread extends Thread {
+ public void doWork(final CountDownLatch latch) {
+
+ Thread thread = new Thread() {
- @Override
- public void run() {
+ /**
+ * Run method adding data to a fictitious database
+ */
+ @Override
+ public void run() {
- try {
System.out.println("Start of the thread");
- Thread.sleep(4000);
- result = true;
+ addDataToDB();
System.out.println("End of the thread method");
-
latch.countDown();
- } catch (InterruptedException e) {
- e.printStackTrace();
}
- }
- }
- /**
- * Start the thread running so that it does some work.
- */
- public void doWork(CountDownLatch latch) {
+ private void addDataToDB() {
+
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ };
- this.latch = latch;
- Thread thread = new MyThread();
thread.start();
System.out.println("Off and running...");
}
-
- /**
- * Retrieve the result.
- */
- public boolean getResult() {
- return result;
- }
}
diff --git a/unit-testing-threads/src/test/java/com/captaindebug/threading/bad_example/ThreadWrapperTest.java b/unit-testing-threads/src/test/java/com/captaindebug/threading/bad_example/ThreadWrapperTest.java
index 2a5c4ca..dab2f77 100644
--- a/unit-testing-threads/src/test/java/com/captaindebug/threading/bad_example/ThreadWrapperTest.java
+++ b/unit-testing-threads/src/test/java/com/captaindebug/threading/bad_example/ThreadWrapperTest.java
@@ -15,8 +15,14 @@ public void testDoWork() throws InterruptedException {
Thread.sleep(10000);
- boolean result = instance.getResult();
+ boolean result = getResultFromDatabase();
assertTrue(result);
}
+ /**
+ * Dummy database method - just return true
+ */
+ private boolean getResultFromDatabase() {
+ return true;
+ }
}
diff --git a/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example/ThreadWrapperTest.java b/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example/ThreadWrapperTest.java
index 9a7679d..70faf83 100644
--- a/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example/ThreadWrapperTest.java
+++ b/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example/ThreadWrapperTest.java
@@ -17,8 +17,14 @@ public void testDoWork() throws InterruptedException {
instance.doWork(latch);
latch.await();
- boolean result = instance.getResult();
+ boolean result = getResultFromDatabase();
assertTrue(result);
}
+ /**
+ * Dummy database method - just return true
+ */
+ private boolean getResultFromDatabase() {
+ return true;
+ }
}
From fc30aea66c8db59e88e98b942d8e498289382029 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sat, 26 Jan 2013 22:16:18 +0000
Subject: [PATCH 012/142] Added additional examples and test.
---
unit-testing-threads/pom.xml | 10 ++-
.../good_example2/ThreadWrapper.java | 69 +++++++++++++++++++
.../threading/good_example2/package-info.java | 10 +++
.../threading/strategy/DatabaseJob.java | 24 +++++++
.../threading/strategy/ThreadWrapper.java | 24 +++++++
.../threading/strategy/package-info.java | 10 +++
.../good_example2/ThreadWrapperTest.java | 30 ++++++++
.../threading/strategy/ThreadWrapperTest.java | 48 +++++++++++++
8 files changed, 222 insertions(+), 3 deletions(-)
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/ThreadWrapper.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/package-info.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/DatabaseJob.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/ThreadWrapper.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/package-info.java
create mode 100644 unit-testing-threads/src/test/java/com/captaindebug/threading/good_example2/ThreadWrapperTest.java
create mode 100644 unit-testing-threads/src/test/java/com/captaindebug/threading/strategy/ThreadWrapperTest.java
diff --git a/unit-testing-threads/pom.xml b/unit-testing-threads/pom.xml
index 3ceb32a..f3ccb9f 100644
--- a/unit-testing-threads/pom.xml
+++ b/unit-testing-threads/pom.xml
@@ -38,7 +38,11 @@
4.8.2test
-
+
+ com.google.guava
+ guava
+ 11.0.1
+
@@ -47,8 +51,8 @@
maven-compiler-plugin2.3.2
- 1.6
- 1.6
+ 1.7
+ 1.7
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/ThreadWrapper.java
new file mode 100644
index 0000000..e57fc7e
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/ThreadWrapper.java
@@ -0,0 +1,69 @@
+/**
+ *
+ */
+package com.captaindebug.threading.good_example2;
+
+import java.util.concurrent.CountDownLatch;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * @author Roger
+ *
+ * Created 18:35:58 20 Jan 2013
+ *
+ */
+public class ThreadWrapper {
+
+ /**
+ * Start the thread running so that it does some work.
+ */
+ public void doWork() {
+ doWork(null);
+ }
+
+ /**
+ * Start the thread running so that it does some work.
+ */
+ @VisibleForTesting
+ void doWork(final CountDownLatch latch) {
+
+ Thread thread = new Thread() {
+
+ /**
+ * Run method adding data to a fictitious database
+ */
+ @Override
+ public void run() {
+
+ System.out.println("Start of the thread");
+ addDataToDB();
+ System.out.println("End of the thread method");
+ countDown();
+ }
+
+ private void addDataToDB() {
+
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void countDown() {
+ if (isNotNull(latch)) {
+ latch.countDown();
+ }
+ }
+
+ private boolean isNotNull(Object obj) {
+ return latch != null;
+ }
+
+ };
+
+ thread.start();
+ System.out.println("Off and running...");
+ }
+}
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/package-info.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/package-info.java
new file mode 100644
index 0000000..5953362
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/package-info.java
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+/**
+ * @author Roger
+ *
+ * Created 20:45:26 26 Jan 2013
+ *
+ */
+package com.captaindebug.threading.good_example2;
\ No newline at end of file
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/DatabaseJob.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/DatabaseJob.java
new file mode 100644
index 0000000..c1bc80a
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/DatabaseJob.java
@@ -0,0 +1,24 @@
+package com.captaindebug.threading.strategy;
+
+public class DatabaseJob implements Runnable {
+
+ /**
+ * Run method adding data to a fictitious database
+ */
+ @Override
+ public void run() {
+
+ System.out.println("Start of the thread");
+ addDataToDB();
+ System.out.println("End of the thread method");
+ }
+
+ private void addDataToDB() {
+
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/ThreadWrapper.java
new file mode 100644
index 0000000..6dd6e05
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/ThreadWrapper.java
@@ -0,0 +1,24 @@
+/**
+ *
+ */
+package com.captaindebug.threading.strategy;
+
+
+/**
+ * @author Roger
+ *
+ * Created 18:35:58 20 Jan 2013
+ *
+ */
+public class ThreadWrapper {
+
+ /**
+ * Start the thread running so that it does some work.
+ */
+ public void doWork(Runnable job) {
+
+ Thread thread = new Thread(job);
+ thread.start();
+ System.out.println("Off and running...");
+ }
+}
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/package-info.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/package-info.java
new file mode 100644
index 0000000..12b05c2
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/strategy/package-info.java
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+/**
+ * @author Roger
+ *
+ * Created 21:20:40 26 Jan 2013
+ *
+ */
+package com.captaindebug.threading.strategy;
\ No newline at end of file
diff --git a/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example2/ThreadWrapperTest.java b/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example2/ThreadWrapperTest.java
new file mode 100644
index 0000000..cc587a8
--- /dev/null
+++ b/unit-testing-threads/src/test/java/com/captaindebug/threading/good_example2/ThreadWrapperTest.java
@@ -0,0 +1,30 @@
+package com.captaindebug.threading.good_example2;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.Test;
+
+public class ThreadWrapperTest {
+
+ @Test
+ public void testDoWork() throws InterruptedException {
+
+ ThreadWrapper instance = new ThreadWrapper();
+
+ CountDownLatch latch = new CountDownLatch(1);
+
+ instance.doWork(latch);
+ latch.await();
+ boolean result = getResultFromDatabase();
+ assertTrue(result);
+ }
+
+ /**
+ * Dummy database method - just return true
+ */
+ private boolean getResultFromDatabase() {
+ return true;
+ }
+}
diff --git a/unit-testing-threads/src/test/java/com/captaindebug/threading/strategy/ThreadWrapperTest.java b/unit-testing-threads/src/test/java/com/captaindebug/threading/strategy/ThreadWrapperTest.java
new file mode 100644
index 0000000..71e738a
--- /dev/null
+++ b/unit-testing-threads/src/test/java/com/captaindebug/threading/strategy/ThreadWrapperTest.java
@@ -0,0 +1,48 @@
+package com.captaindebug.threading.strategy;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.Test;
+
+public class ThreadWrapperTest {
+
+ @Test
+ public void testDoWork() throws InterruptedException {
+
+ ThreadWrapper instance = new ThreadWrapper();
+
+ CountDownLatch latch = new CountDownLatch(1);
+
+ DatabaseJobTester tester = new DatabaseJobTester(latch);
+ instance.doWork(tester);
+ latch.await();
+
+ boolean result = getResultFromDatabase();
+ assertTrue(result);
+ }
+
+ /**
+ * Dummy database method - just return true
+ */
+ private boolean getResultFromDatabase() {
+ return true;
+ }
+
+ private class DatabaseJobTester extends DatabaseJob {
+
+ private final CountDownLatch latch;
+
+ public DatabaseJobTester(CountDownLatch latch) {
+ super();
+ this.latch = latch;
+ }
+
+ @Override
+ public void run() {
+ super.run();
+ latch.countDown();
+ }
+ }
+}
From b3d8ac9992b46896c55c100214aa9650c4ab686c Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sun, 27 Jan 2013 11:59:25 +0000
Subject: [PATCH 013/142] Completed unit testing threads example code.
---
unit-testing-threads/pom.xml | 2 +-
.../threading/bad_example/ThreadWrapper.java | 2 +-
.../threading/good_example/ThreadWrapper.java | 12 +++++++++++-
.../threading/good_example2/ThreadWrapper.java | 3 ---
4 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/unit-testing-threads/pom.xml b/unit-testing-threads/pom.xml
index f3ccb9f..5bdf4af 100644
--- a/unit-testing-threads/pom.xml
+++ b/unit-testing-threads/pom.xml
@@ -41,7 +41,7 @@
com.google.guavaguava
- 11.0.1
+ 13.0.1
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java
index 21b6722..512022d 100644
--- a/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/ThreadWrapper.java
@@ -30,7 +30,7 @@ public void run() {
}
private void addDataToDB() {
-
+ // Dummy Code...
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java
index 6cd21d6..7cce567 100644
--- a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/ThreadWrapper.java
@@ -29,7 +29,7 @@ public void run() {
System.out.println("Start of the thread");
addDataToDB();
System.out.println("End of the thread method");
- latch.countDown();
+ countDown();
}
private void addDataToDB() {
@@ -41,6 +41,16 @@ private void addDataToDB() {
}
}
+ private void countDown() {
+ if (isNotNull(latch)) {
+ latch.countDown();
+ }
+ }
+
+ private boolean isNotNull(Object obj) {
+ return latch != null;
+ }
+
};
thread.start();
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/ThreadWrapper.java
index e57fc7e..ce408bd 100644
--- a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/ThreadWrapper.java
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/ThreadWrapper.java
@@ -22,9 +22,6 @@ public void doWork() {
doWork(null);
}
- /**
- * Start the thread running so that it does some work.
- */
@VisibleForTesting
void doWork(final CountDownLatch latch) {
From 3fb3a6d1ab339eba0207a145d993e690a6c7426d Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sun, 3 Feb 2013 18:14:55 +0000
Subject: [PATCH 014/142] Initial incomplete check in of producer consumer
pattern example
---
producer-consumer/pom.xml | 60 +++++++
.../captaindebug/producerconsumer/Main.java | 5 +
.../captaindebug/producerconsumer/Match.java | 70 ++++++++
.../producerconsumer/MatchReporter.java | 5 +
.../producerconsumer/Message.java | 48 ++++++
.../producerconsumer/Teletype.java | 5 +
.../src/main/resources/matches.xml | 158 ++++++++++++++++++
.../producerconsumer/MatchTest.java | 88 ++++++++++
8 files changed, 439 insertions(+)
create mode 100644 producer-consumer/pom.xml
create mode 100644 producer-consumer/src/main/java/com/captaindebug/producerconsumer/Main.java
create mode 100644 producer-consumer/src/main/java/com/captaindebug/producerconsumer/Match.java
create mode 100644 producer-consumer/src/main/java/com/captaindebug/producerconsumer/MatchReporter.java
create mode 100644 producer-consumer/src/main/java/com/captaindebug/producerconsumer/Message.java
create mode 100644 producer-consumer/src/main/java/com/captaindebug/producerconsumer/Teletype.java
create mode 100644 producer-consumer/src/main/resources/matches.xml
create mode 100644 producer-consumer/src/test/java/com/captaindebug/producerconsumer/MatchTest.java
diff --git a/producer-consumer/pom.xml b/producer-consumer/pom.xml
new file mode 100644
index 0000000..b902808
--- /dev/null
+++ b/producer-consumer/pom.xml
@@ -0,0 +1,60 @@
+
+
+ 4.0.0
+ com.captaindebug
+ producer-consumer
+ jar
+ 1.0-SNAPSHOT
+ Example Producer Consumer Pattern
+
+ 1.6.1
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4jVersion}
+
+
+
+ org.slf4j
+ slf4j-log4j12
+ ${slf4jVersion}
+ runtime
+
+
+ log4j
+ log4j
+ 1.2.16
+ runtime
+
+
+ junit
+ junit
+ 4.8.2
+ test
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.7
+ 1.7
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.6
+
+
+
+
diff --git a/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Main.java b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Main.java
new file mode 100644
index 0000000..fd1cab8
--- /dev/null
+++ b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Main.java
@@ -0,0 +1,5 @@
+package com.captaindebug.producerconsumer;
+
+public class Main {
+
+}
diff --git a/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Match.java b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Match.java
new file mode 100644
index 0000000..538d101
--- /dev/null
+++ b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Match.java
@@ -0,0 +1,70 @@
+package com.captaindebug.producerconsumer;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class Match {
+
+ private final String name;
+
+ private final List updates;
+
+ public Match(String name, List matchInfo) {
+
+ this.name = name;
+ this.updates = new ArrayList();
+ createUpdateList(matchInfo);
+ }
+
+ private void createUpdateList(List matchInfo) {
+
+ createMessageList(matchInfo);
+ Collections.sort(updates);
+ }
+
+ private void createMessageList(List matchInfo) {
+
+ for (String rawMessage : matchInfo) {
+
+ final long time = getMessageTime(rawMessage);
+ final String messageText = getMessageText(rawMessage);
+ Message message = new Message(name, time, messageText);
+ updates.add(message);
+ }
+ }
+
+ private long getMessageTime(String rawMessage) {
+
+ String timeString = getTime(rawMessage);
+ long time = parseTime(timeString);
+ return time;
+ }
+
+ private String getTime(String rawMessage) {
+ int index = rawMessage.indexOf(' ');
+ String retVal = rawMessage.substring(0, index);
+ return retVal;
+ }
+
+ private long parseTime(String timeString) {
+ String[] split = timeString.split(":");
+ long time = ((new Long(split[0]) * 60) + new Long(split[1])) * 10;
+ return time;
+ }
+
+ private String getMessageText(String rawMessage) {
+
+ int index = rawMessage.indexOf(' ');
+ String retVal = rawMessage.substring(index + 1);
+ return retVal;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List getUpdates() {
+ return Collections.unmodifiableList(updates);
+ }
+}
diff --git a/producer-consumer/src/main/java/com/captaindebug/producerconsumer/MatchReporter.java b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/MatchReporter.java
new file mode 100644
index 0000000..3b9f167
--- /dev/null
+++ b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/MatchReporter.java
@@ -0,0 +1,5 @@
+package com.captaindebug.producerconsumer;
+
+public class MatchReporter {
+
+}
diff --git a/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Message.java b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Message.java
new file mode 100644
index 0000000..652668f
--- /dev/null
+++ b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Message.java
@@ -0,0 +1,48 @@
+package com.captaindebug.producerconsumer;
+
+/**
+ * A simple message that contains a match update, which is placed on the queue.
+ *
+ * @author Roger
+ *
+ * Created 16:24:19 3 Feb 2013
+ *
+ */
+public class Message implements Comparable {
+
+ private final String name;
+ private final long time;
+ private final String messageText;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getMessageText() {
+ return messageText;
+ }
+
+ public long getTime() {
+ return time;
+ }
+
+ public Message(String name, long time, String messageText) {
+ this.name = name;
+ this.time = time;
+ this.messageText = messageText;
+ }
+
+ /**
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ *
+ * @return a negative integer, zero, or a positive integer as this object is
+ * less than, equal to, or greater than the specified object
+ */
+ @Override
+ public int compareTo(Message compareTime) {
+
+ int retVal = (int) (time - compareTime.time);
+
+ return retVal;
+ }
+}
diff --git a/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Teletype.java b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Teletype.java
new file mode 100644
index 0000000..7b6d5a1
--- /dev/null
+++ b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/Teletype.java
@@ -0,0 +1,5 @@
+package com.captaindebug.producerconsumer;
+
+public class Teletype {
+
+}
diff --git a/producer-consumer/src/main/resources/matches.xml b/producer-consumer/src/main/resources/matches.xml
new file mode 100644
index 0000000..cca67c9
--- /dev/null
+++ b/producer-consumer/src/main/resources/matches.xml
@@ -0,0 +1,158 @@
+Fulham vs Manchester United
+
+95:00 Final Score Fulham 0 - 1 Man Utd
+94:59 Full time The referee signals the end of the game.
+90:00 +3:52 Unfair challenge on Mladen Petric by Danny Welbeck results in a free kick. Shot comes in from Hugo Rodallega from the free kick.
+92:07 David De Gea restarts play with the free kick.
+92:07 Booking Wayne Rooney shown a yellow card.
+91:56 Patrice Evra fouled by Damien Duff, the ref awards a free kick.
+90:43 Urby Emanuelson takes a shot. Rio Ferdinand gets a block in. John Arne Riise takes the outswinging corner, Philippe Senderos takes a shot. Robin van Persie makes a clearance.
+89:39 Unfair challenge on Philippe Senderos by Javier Hernandez results in a free kick. Free kick taken by Mark Schwarzer.
+89:04 Mladen Petric gives away a free kick for an unfair challenge on Michael Carrick. Direct free kick taken by David De Gea. 87:53 Bryan Ruiz takes a shot. Wayne Rooney gets a block in. 84:32 Urby Emanuelson challenges Javier Hernandez unfairly and gives away a free kick. Free kick crossed by Ryan Giggs, clearance by Sascha Riether.
+83:09 Mark Schwarzer takes the indirect free kick.
+83:09 Substitution Danny Welbeck is brought on as a substitute for Luis Nani.
+83:09 The offside flag is raised against Robin van Persie.
+80:55 Substitution Mladen Petric on for Ashkan Dejagah. 80:55 Outswinging corner taken left-footed by Damien Duff from the left by-line, Hugo Rodallega has a headed effort at goal from deep inside the area missing to the left of the target.
+78:09 Assist on the goal came from Jonny Evans.
+78:09 Goal - Wayne Rooney - Fulham 0 - 1 Man Utd Wayne Rooney fires in a goal from the edge of the area to the bottom right corner of the goal. Fulham 0-1 Man Utd.
+78:09 The assist for the goal came from Jonny Evans.
+78:09 Goal scored - Wayne Rooney - Fulham 0 - 1 Man Utd Wayne Rooney grabs a goal from the edge of the penalty box to the bottom right corner of the goal. Fulham 0-1 Man Utd.
+76:38 Free kick awarded for a foul by Jonny Evans on Bryan Ruiz. John Arne Riise restarts play with the free kick, Chris Baird produces a right-footed shot from outside the penalty box and misses right.
+75:54 Outswinging corner taken left-footed by Damien Duff, Chris Baird takes a shot. Clearance by Rafael Da Silva.
+74:19 Substitution Ryan Giggs is brought on as a substitute for Tom Cleverley.
+72:19 Header by Ashkan Dejagah from deep inside the penalty area misses to the left of the target.
+70:54 Sascha Riether takes a shot. Save by David De Gea.
+68:58 Inswinging corner taken left-footed by Robin van Persie from the right by-line, clearance by Chris Baird.
+66:47 Free kick crossed right-footed by Luis Nani from right channel, John Arne Riise makes a clearance.
+66:47 Substitution Urby Emanuelson is brought on as a substitute for Giorgos Karagounis.
+66:47 Free kick awarded for an unfair challenge on Robin van Persie by Chris Baird.
+64:44 Shot comes in from Robin van Persie from the free kick, comfortable save by Mark Schwarzer.
+64:44 Substitution Javier Hernandez comes on in place of Antonio Valencia.
+64:44 Booking for Chris Baird.
+64:40 Chris Baird challenges Antonio Valencia unfairly and gives away a free kick.
+63:33 Luis Nani takes a shot. Philippe Senderos gets a block in. Inswinging corner taken by Wayne Rooney from the left by-line, Bryan Ruiz manages to make a clearance.
+62:29 The assistant referee flags for offside against Luis Nani. Indirect free kick taken by Mark Schwarzer.
+62:13 Shot from 25 yards from Chris Baird. Save by David De Gea.
+60:40 Rafael Da Silva concedes a free kick for a foul on Bryan Ruiz. Giorgos Karagounis takes the direct free kick.
+59:51 Hugo Rodallega is ruled offside. Rio Ferdinand restarts play with the free kick.
+57:59 Robin van Persie is ruled offside. Indirect free kick taken by Mark Schwarzer.
+55:47 Effort on goal by Rafael Da Silva from just outside the penalty area goes harmlessly over the target.
+55:08 Giorgos Karagounis produces a right-footed shot from just outside the box that goes wide left of the target.
+52:43 Foul by Antonio Valencia on John Arne Riise, free kick awarded. Direct free kick taken by John Arne Riise.
+51:54 The referee blows for offside against Antonio Valencia. Indirect free kick taken by Mark Schwarzer.
+50:51 The referee penalises Ashkan Dejagah for handball. Wayne Rooney takes the direct free kick.
+49:03 Rafael Da Silva gives away a free kick for an unfair challenge on John Arne Riise. Giorgos Karagounis takes the direct free kick.
+48:37 Robin van Persie takes a shot. Mark Schwarzer makes a save.
+47:12 Ashkan Dejagah is ruled offside. David De Gea takes the free kick.
+46:34 Centre by Antonio Valencia.
+46:01 Robin van Persie challenges Giorgos Karagounis unfairly and gives away a free kick. Chris Baird restarts play with the free kick.
+45:01 The game restarts for the second half.
+45:01 Substitution Aaron Hughes is brought on as a substitute for Brede Hangeland.
+45:00 Half time The half-time whistle blows.
+43:13 Robin van Persie takes a shot. Save by Mark Schwarzer.
+42:07 The ball is delivered by Robin van Persie, John Arne Riise makes a clearance. Corner taken left-footed by Robin van Persie from the right by-line, clearance by Brede Hangeland.
+39:41 Antonio Valencia crosses the ball.
+38:47 Foul by Wayne Rooney on Ashkan Dejagah, free kick awarded. The free kick is swung in left-footed by Damien Duff, Jonny Evans manages to make a clearance.
+37:40 Ashkan Dejagah fouled by Patrice Evra, the ref awards a free kick. Free kick crossed left-footed by Damien Duff from right channel, Jonny Evans makes a clearance.
+33:02 Luis Nani produces a curled right-footed shot from 18 yards. Blocked by Philippe Senderos. Corner taken left-footed by Robin van Persie from the right by-line, clearance made by Brede Hangeland. Jonny Evans challenges Brede Hangeland unfairly and gives away a free kick. Free kick taken by Mark Schwarzer.
+31:52 Wayne Rooney takes a shot.
+29:06 Free kick awarded for an unfair challenge on Ashkan Dejagah by Luis Nani. Free kick taken by Mark Schwarzer.
+27:36 Centre by Damien Duff, clearance by Rio Ferdinand.
+27:02 Inswinging corner taken by Damien Duff from the right by-line, clearance by Robin van Persie.
+24:36 Inswinging corner taken by Wayne Rooney from the left by-line, clearance by Brede Hangeland.
+23:44 Unfair challenge on Bryan Ruiz by Robin van Persie results in a free kick. Free kick taken by Bryan Ruiz.
+21:55 Damien Duff gives away a free kick for an unfair challenge on Tom Cleverley. Robin van Persie delivers the ball from the free kick left-footed from right channel, clearance by Bryan Ruiz.
+20:20 Foul by Luis Nani on Giorgos Karagounis, free kick awarded. Direct free kick taken by Chris Baird.
+19:46 Antonio Valencia crosses the ball, blocked by John Arne Riise.
+18:47 Wayne Rooney produces a right-footed shot from the edge of the area and misses to the left of the target.
+18:36 Brede Hangeland gives away a free kick for an unfair challenge on Luis Nani. Patrice Evra takes the free kick.
+15:05 Antonio Valencia produces a right-footed shot from deep inside the penalty box which goes wide of the right-hand upright.
+17:27 The assistant referee signals for offside against Robin van Persie. Mark Schwarzer takes the free kick.
+17:04 Ashkan Dejagah produces a right-footed shot from the edge of the box and misses to the right of the target.
+16:32 Bryan Ruiz fouled by Patrice Evra, the ref awards a free kick. The free kick is delivered left-footed by Bryan Ruiz from right wing, Rio Ferdinand makes a clearance.
+15:05 Effort from inside the area by Luis Nani misses to the right of the target.
+14:52 Corner taken right-footed by Wayne Rooney from the left by-line, Brede Hangeland manages to make a clearance.
+14:19 Bryan Ruiz takes a shot.
+13:51 Centre by Luis Nani, clearance made by Philippe Senderos.
+12:09 The assistant referee signals for offside against Antonio Valencia. Mark Schwarzer takes the indirect free kick.
+11:14 John Arne Riise has a drilled shot. Save by David De Gea. Inswinging corner taken left-footed by Damien Duff, save by David De Gea.
+10:21 Rafael Da Silva sends in a cross, blocked by Brede Hangeland.
+7:17 Inswinging corner taken left-footed by Robin van Persie from the right by-line, Patrice Evra takes a shot. Patrice Evra takes a shot. Save by Mark Schwarzer.
+7:03 The ball is sent over by Wayne Rooney.
+6:16 Luis Nani takes a shot. Blocked by Sascha Riether. Inswinging corner taken by Wayne Rooney, Mark Schwarzer makes a save.
+5:25 Bryan Ruiz concedes a free kick for a foul on Patrice Evra. David De Gea takes the free kick.
+4:53 The ball is delivered by Rafael Da Silva, save by Mark Schwarzer.
+4:00 Ashkan Dejagah takes a shot.
+1:24 Free kick awarded for an unfair challenge on Giorgos Karagounis by Tom Cleverley. Philippe Senderos takes the free kick.
+0:45 A cross is delivered by Luis Nani, Giorgos Karagounis gets a block in.
+0:00 The referee gets the match started.
+
+
+
+
+
+
+
+
+Arsenal vs Stoke City
+
+95:22 Final Score Arsenal 1 - 0 Stoke
+95:21 Full time The referee blows his whistle to end the game.
+94:06 Unfair challenge on Laurent Koscielny by Kenwyne Jones results in a free kick. Wojciech Szczesny takes the free kick.
+92:40 Michael Owen gives away a free kick for an unfair challenge on Mikel Arteta. Direct free kick taken by Mikel Arteta.
+89:58 Laurent Koscielny restarts play with the free kick.
+89:58 Substitution Theo Walcott goes off and Aaron Ramsey comes on.
+89:58 Nacho Monreal fouled by Cameron Jerome, the ref awards a free kick.
+88:10 Mikel Arteta restarts play with the free kick.
+88:10 Booking Ryan Shawcross is given a yellow card.
+88:04 Free kick awarded for a foul by Ryan Shawcross on Laurent Koscielny.
+82:39 Ryan Shawcross takes the free kick.
+82:39 Substitution (Stoke) makes a substitution, with Michael Owen coming on for Geoff Cameron.
+82:39 Substitution Jonathan Walters goes off and Cameron Jerome comes on.
+82:39 Substitution Kenwyne Jones is brought on as a substitute for Peter Crouch.
+82:39 Laurent Koscielny challenges Peter Crouch unfairly and gives away a free kick.
+80:50 Jack Wilshere takes the inswinging corner, Ryan Shawcross manages to make a clearance.
+79:48 Santi Cazorla takes a shot. Save by Asmir Begovic. Theo Walcott decides to take a short corner.
+79:41 Santi Cazorla takes a shot. Blocked by Ryan Shawcross. Santi Cazorla takes a shot. Blocked by Ryan Shawcross.
+77:11 Assist on the goal came from Theo Walcott.
+77:11 Goal scored. Goal - Lukas Podolski - Arsenal 1 - 0 Stoke Lukas Podolski grabs a goal direct from the free kick from just outside the area low into the middle of the goal. Arsenal 1-0 Stoke.
+76:14 Booking Andy Wilkinson is given a yellow card.
+75:57 Unfair challenge on Theo Walcott by Andy Wilkinson results in a free kick.
+74:12 The assistant referee signals for offside against Peter Crouch. Laurent Koscielny restarts play with the free kick.
+73:27 Shot from long distance by Nacho Monreal misses to the right of the goal.
+71:38 Headed effort from deep inside the area by Olivier Giroud misses to the right of the goal.
+69:42 Direct free kick taken by Jack Wilshere.
+69:42 Booking Glenn Whelan booked for unsporting behaviour.
+69:32 Santi Cazorla fouled by Glenn Whelan, the ref awards a free kick.
+68:46 Bacary Sagna challenges Matthew Etherington unfairly and gives away a free kick. Free kick crossed left-footed by Matthew Etherington from left wing, clearance made by Per Mertesacker.
+67:22 Substitution Santi Cazorla replaces Vassiriki Diaby.
+67:22 Substitution Lukas Podolski comes on in place of Alex Oxlade-Chamberlain.
+63:48 Ryan Shawcross has an effort at goal from just outside the area which goes wide of the left-hand post.
+61:09 Geoff Cameron is caught offside. Laurent Koscielny takes the indirect free kick.
+55:18 Effort on goal by Olivier Giroud from deep inside the area goes harmlessly over the bar.
+51:04 Ryan Shotton concedes a free kick for a foul on Alex Oxlade-Chamberlain. Jack Wilshere takes the free kick.
+50:20 Free kick awarded for an unfair challenge on Jack Wilshere by Robert Huth. Mikel Arteta takes the direct free kick.
+48:59 Inswinging corner taken by Theo Walcott, Asmir Begovic makes a save.
+46:45 Unfair challenge on Mikel Arteta by Peter Crouch results in a free kick. Mikel Arteta takes the free kick. 45:01 The referee gets the second half underway.
+48:23 Half time
+40:01 Alex Oxlade-Chamberlain takes a shot. Save made by Asmir Begovic. Corner from the right by-line taken by Jack Wilshere, clearance made by Steven Nzonzi. Inswinging corner taken right-footed by Theo Walcott from the left by-line, clearance by Peter Crouch.
+38:25 Olivier Giroud is caught offside. Asmir Begovic restarts play with the free kick.
+34:31 Laurent Koscielny takes a shot. Asmir Begovic makes a save.
+33:58 Inswinging corner taken by Theo Walcott from the left by-line, Peter Crouch manages to make a clearance.
+30:39 Corner taken by Jack Wilshere from the right by-line, Alex Oxlade-Chamberlain takes a shot. Save by Asmir Begovic. Inswinging corner taken by Theo Walcott, Peter Crouch makes a clearance.
+29:36 Unfair challenge on Olivier Giroud by Ryan Shawcross results in a free kick. Free kick taken by Mikel Arteta.
+29:04 Effort on goal by Ryan Shawcross from just outside the area goes harmlessly over the target.
+25:37 Theo Walcott takes a shot. Blocked by Andy Wilkinson. Foul by Mikel Arteta on Geoff Cameron, free kick awarded. Free kick taken by Asmir Begovic.
+22:35 Corner from the right by-line taken by Jack Wilshere, save made by Asmir Begovic.
+21:50 Shot from just outside the box by Glenn Whelan goes over the bar.
+20:51 Alex Oxlade-Chamberlain takes a shot. Ryan Shawcross gets a block in. Olivier Giroud is caught offside. Asmir Begovic takes the free kick.
+17:04 Headed effort from the edge of the area by Ryan Shawcross goes wide of the right-hand post. Free kick awarded for an unfair challenge on Theo Walcott by Andy Wilkinson. Jack Wilshere crosses the ball from the free kick left-footed from right wing, Robert Huth manages to make a clearance.
+16:33 Peter Crouch takes a shot. Laurent Koscielny gets a block in. Inswinging corner taken by Matthew Etherington.
+14:38 Olivier Giroud produces a headed effort from deep inside the six-yard box which goes wide of the right-hand upright.
+13:49 Jonathan Walters takes a shot. Wojciech Szczesny makes a save.
+12:29 Free kick awarded for an unfair challenge on Theo Walcott by Matthew Etherington. Bacary Sagna takes the free kick.
+6:15 Corner from the right by-line taken by Jack Wilshere, Geoff Cameron manages to make a clearance. Inswinging corner taken left-footed by Jack Wilshere played to the near post, Glenn Whelan manages to make a clearance.
+4:57 Jack Wilshere takes a shot from inside the box clearing the bar.
+1:57 Effort from the edge of the area by Alex Oxlade-Chamberlain goes wide of the left-hand upright.
+1:06 Free kick awarded for an unfair challenge on Jack Wilshere by Geoff Cameron. Mikel Arteta restarts play with the free kick.
+0:00 The match has kicked off.
\ No newline at end of file
diff --git a/producer-consumer/src/test/java/com/captaindebug/producerconsumer/MatchTest.java b/producer-consumer/src/test/java/com/captaindebug/producerconsumer/MatchTest.java
new file mode 100644
index 0000000..1b9b666
--- /dev/null
+++ b/producer-consumer/src/test/java/com/captaindebug/producerconsumer/MatchTest.java
@@ -0,0 +1,88 @@
+package com.captaindebug.producerconsumer;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+
+public class MatchTest {
+
+ private static final String MATCH_NAME = "Man City vs Stoke";
+
+ private static final String UPDATE_TEXT = "This is an update";
+
+ private static final String DATA1 = "55:00 " + UPDATE_TEXT;
+
+ private static final String DATA2 = "25:00 " + UPDATE_TEXT;
+
+ private Match instance;
+
+ @Test
+ public void testGetUpdates() {
+
+ List arg1 = Arrays.asList(DATA1);
+ instance = new Match(MATCH_NAME, arg1);
+
+ List results = instance.getUpdates();
+
+ assertEquals(1, results.size());
+
+ final long expectedTime = 55 * 600;
+
+ Message result = results.get(0);
+ assertEquals(expectedTime, result.getTime());
+
+ assertEquals(UPDATE_TEXT, result.getMessageText());
+
+ assertEquals(MATCH_NAME, result.getName());
+ }
+
+ @Test
+ public void testGetUpdates_and_check_sort_order1() {
+
+ List arg1 = Arrays.asList(DATA1, DATA2);
+ instance = new Match(MATCH_NAME, arg1);
+
+ List results = instance.getUpdates();
+
+ assertEquals(2, results.size());
+
+ long expectedTime = 25 * 600;
+ Message result = results.get(0);
+ assertEquals(expectedTime, result.getTime());
+ assertEquals(UPDATE_TEXT, result.getMessageText());
+ assertEquals(MATCH_NAME, result.getName());
+
+ expectedTime = 55 * 600;
+ result = results.get(1);
+ assertEquals(expectedTime, result.getTime());
+ assertEquals(UPDATE_TEXT, result.getMessageText());
+ assertEquals(MATCH_NAME, result.getName());
+ }
+
+ @Test
+ public void testGetUpdates_and_check_sort_order2() {
+
+ List arg1 = Arrays.asList(DATA2, DATA1);
+ instance = new Match(MATCH_NAME, arg1);
+
+ List results = instance.getUpdates();
+
+ assertEquals(2, results.size());
+
+ long expectedTime = 25 * 600;
+ Message result = results.get(0);
+ assertEquals(expectedTime, result.getTime());
+ assertEquals(UPDATE_TEXT, result.getMessageText());
+ assertEquals(MATCH_NAME, result.getName());
+
+ expectedTime = 55 * 600;
+ result = results.get(1);
+ assertEquals(expectedTime, result.getTime());
+ assertEquals(UPDATE_TEXT, result.getMessageText());
+ assertEquals(MATCH_NAME, result.getName());
+ }
+
+}
From 447388f1246e6793c9a09ad21ff0d73c8f4debd5 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sun, 3 Feb 2013 19:28:09 +0000
Subject: [PATCH 015/142] Update Spring config file (not yet complete).
---
.../src/main/resources/matches.xml | 331 +++++++++---------
1 file changed, 175 insertions(+), 156 deletions(-)
diff --git a/producer-consumer/src/main/resources/matches.xml b/producer-consumer/src/main/resources/matches.xml
index cca67c9..155a914 100644
--- a/producer-consumer/src/main/resources/matches.xml
+++ b/producer-consumer/src/main/resources/matches.xml
@@ -1,158 +1,177 @@
-Fulham vs Manchester United
+
+
-95:00 Final Score Fulham 0 - 1 Man Utd
-94:59 Full time The referee signals the end of the game.
-90:00 +3:52 Unfair challenge on Mladen Petric by Danny Welbeck results in a free kick. Shot comes in from Hugo Rodallega from the free kick.
-92:07 David De Gea restarts play with the free kick.
-92:07 Booking Wayne Rooney shown a yellow card.
-91:56 Patrice Evra fouled by Damien Duff, the ref awards a free kick.
-90:43 Urby Emanuelson takes a shot. Rio Ferdinand gets a block in. John Arne Riise takes the outswinging corner, Philippe Senderos takes a shot. Robin van Persie makes a clearance.
-89:39 Unfair challenge on Philippe Senderos by Javier Hernandez results in a free kick. Free kick taken by Mark Schwarzer.
-89:04 Mladen Petric gives away a free kick for an unfair challenge on Michael Carrick. Direct free kick taken by David De Gea. 87:53 Bryan Ruiz takes a shot. Wayne Rooney gets a block in. 84:32 Urby Emanuelson challenges Javier Hernandez unfairly and gives away a free kick. Free kick crossed by Ryan Giggs, clearance by Sascha Riether.
-83:09 Mark Schwarzer takes the indirect free kick.
-83:09 Substitution Danny Welbeck is brought on as a substitute for Luis Nani.
-83:09 The offside flag is raised against Robin van Persie.
-80:55 Substitution Mladen Petric on for Ashkan Dejagah. 80:55 Outswinging corner taken left-footed by Damien Duff from the left by-line, Hugo Rodallega has a headed effort at goal from deep inside the area missing to the left of the target.
-78:09 Assist on the goal came from Jonny Evans.
-78:09 Goal - Wayne Rooney - Fulham 0 - 1 Man Utd Wayne Rooney fires in a goal from the edge of the area to the bottom right corner of the goal. Fulham 0-1 Man Utd.
-78:09 The assist for the goal came from Jonny Evans.
-78:09 Goal scored - Wayne Rooney - Fulham 0 - 1 Man Utd Wayne Rooney grabs a goal from the edge of the penalty box to the bottom right corner of the goal. Fulham 0-1 Man Utd.
-76:38 Free kick awarded for a foul by Jonny Evans on Bryan Ruiz. John Arne Riise restarts play with the free kick, Chris Baird produces a right-footed shot from outside the penalty box and misses right.
-75:54 Outswinging corner taken left-footed by Damien Duff, Chris Baird takes a shot. Clearance by Rafael Da Silva.
-74:19 Substitution Ryan Giggs is brought on as a substitute for Tom Cleverley.
-72:19 Header by Ashkan Dejagah from deep inside the penalty area misses to the left of the target.
-70:54 Sascha Riether takes a shot. Save by David De Gea.
-68:58 Inswinging corner taken left-footed by Robin van Persie from the right by-line, clearance by Chris Baird.
-66:47 Free kick crossed right-footed by Luis Nani from right channel, John Arne Riise makes a clearance.
-66:47 Substitution Urby Emanuelson is brought on as a substitute for Giorgos Karagounis.
-66:47 Free kick awarded for an unfair challenge on Robin van Persie by Chris Baird.
-64:44 Shot comes in from Robin van Persie from the free kick, comfortable save by Mark Schwarzer.
-64:44 Substitution Javier Hernandez comes on in place of Antonio Valencia.
-64:44 Booking for Chris Baird.
-64:40 Chris Baird challenges Antonio Valencia unfairly and gives away a free kick.
-63:33 Luis Nani takes a shot. Philippe Senderos gets a block in. Inswinging corner taken by Wayne Rooney from the left by-line, Bryan Ruiz manages to make a clearance.
-62:29 The assistant referee flags for offside against Luis Nani. Indirect free kick taken by Mark Schwarzer.
-62:13 Shot from 25 yards from Chris Baird. Save by David De Gea.
-60:40 Rafael Da Silva concedes a free kick for a foul on Bryan Ruiz. Giorgos Karagounis takes the direct free kick.
-59:51 Hugo Rodallega is ruled offside. Rio Ferdinand restarts play with the free kick.
-57:59 Robin van Persie is ruled offside. Indirect free kick taken by Mark Schwarzer.
-55:47 Effort on goal by Rafael Da Silva from just outside the penalty area goes harmlessly over the target.
-55:08 Giorgos Karagounis produces a right-footed shot from just outside the box that goes wide left of the target.
-52:43 Foul by Antonio Valencia on John Arne Riise, free kick awarded. Direct free kick taken by John Arne Riise.
-51:54 The referee blows for offside against Antonio Valencia. Indirect free kick taken by Mark Schwarzer.
-50:51 The referee penalises Ashkan Dejagah for handball. Wayne Rooney takes the direct free kick.
-49:03 Rafael Da Silva gives away a free kick for an unfair challenge on John Arne Riise. Giorgos Karagounis takes the direct free kick.
-48:37 Robin van Persie takes a shot. Mark Schwarzer makes a save.
-47:12 Ashkan Dejagah is ruled offside. David De Gea takes the free kick.
-46:34 Centre by Antonio Valencia.
-46:01 Robin van Persie challenges Giorgos Karagounis unfairly and gives away a free kick. Chris Baird restarts play with the free kick.
-45:01 The game restarts for the second half.
-45:01 Substitution Aaron Hughes is brought on as a substitute for Brede Hangeland.
-45:00 Half time The half-time whistle blows.
-43:13 Robin van Persie takes a shot. Save by Mark Schwarzer.
-42:07 The ball is delivered by Robin van Persie, John Arne Riise makes a clearance. Corner taken left-footed by Robin van Persie from the right by-line, clearance by Brede Hangeland.
-39:41 Antonio Valencia crosses the ball.
-38:47 Foul by Wayne Rooney on Ashkan Dejagah, free kick awarded. The free kick is swung in left-footed by Damien Duff, Jonny Evans manages to make a clearance.
-37:40 Ashkan Dejagah fouled by Patrice Evra, the ref awards a free kick. Free kick crossed left-footed by Damien Duff from right channel, Jonny Evans makes a clearance.
-33:02 Luis Nani produces a curled right-footed shot from 18 yards. Blocked by Philippe Senderos. Corner taken left-footed by Robin van Persie from the right by-line, clearance made by Brede Hangeland. Jonny Evans challenges Brede Hangeland unfairly and gives away a free kick. Free kick taken by Mark Schwarzer.
-31:52 Wayne Rooney takes a shot.
-29:06 Free kick awarded for an unfair challenge on Ashkan Dejagah by Luis Nani. Free kick taken by Mark Schwarzer.
-27:36 Centre by Damien Duff, clearance by Rio Ferdinand.
-27:02 Inswinging corner taken by Damien Duff from the right by-line, clearance by Robin van Persie.
-24:36 Inswinging corner taken by Wayne Rooney from the left by-line, clearance by Brede Hangeland.
-23:44 Unfair challenge on Bryan Ruiz by Robin van Persie results in a free kick. Free kick taken by Bryan Ruiz.
-21:55 Damien Duff gives away a free kick for an unfair challenge on Tom Cleverley. Robin van Persie delivers the ball from the free kick left-footed from right channel, clearance by Bryan Ruiz.
-20:20 Foul by Luis Nani on Giorgos Karagounis, free kick awarded. Direct free kick taken by Chris Baird.
-19:46 Antonio Valencia crosses the ball, blocked by John Arne Riise.
-18:47 Wayne Rooney produces a right-footed shot from the edge of the area and misses to the left of the target.
-18:36 Brede Hangeland gives away a free kick for an unfair challenge on Luis Nani. Patrice Evra takes the free kick.
-15:05 Antonio Valencia produces a right-footed shot from deep inside the penalty box which goes wide of the right-hand upright.
-17:27 The assistant referee signals for offside against Robin van Persie. Mark Schwarzer takes the free kick.
-17:04 Ashkan Dejagah produces a right-footed shot from the edge of the box and misses to the right of the target.
-16:32 Bryan Ruiz fouled by Patrice Evra, the ref awards a free kick. The free kick is delivered left-footed by Bryan Ruiz from right wing, Rio Ferdinand makes a clearance.
-15:05 Effort from inside the area by Luis Nani misses to the right of the target.
-14:52 Corner taken right-footed by Wayne Rooney from the left by-line, Brede Hangeland manages to make a clearance.
-14:19 Bryan Ruiz takes a shot.
-13:51 Centre by Luis Nani, clearance made by Philippe Senderos.
-12:09 The assistant referee signals for offside against Antonio Valencia. Mark Schwarzer takes the indirect free kick.
-11:14 John Arne Riise has a drilled shot. Save by David De Gea. Inswinging corner taken left-footed by Damien Duff, save by David De Gea.
-10:21 Rafael Da Silva sends in a cross, blocked by Brede Hangeland.
-7:17 Inswinging corner taken left-footed by Robin van Persie from the right by-line, Patrice Evra takes a shot. Patrice Evra takes a shot. Save by Mark Schwarzer.
-7:03 The ball is sent over by Wayne Rooney.
-6:16 Luis Nani takes a shot. Blocked by Sascha Riether. Inswinging corner taken by Wayne Rooney, Mark Schwarzer makes a save.
-5:25 Bryan Ruiz concedes a free kick for a foul on Patrice Evra. David De Gea takes the free kick.
-4:53 The ball is delivered by Rafael Da Silva, save by Mark Schwarzer.
-4:00 Ashkan Dejagah takes a shot.
-1:24 Free kick awarded for an unfair challenge on Giorgos Karagounis by Tom Cleverley. Philippe Senderos takes the free kick.
-0:45 A cross is delivered by Luis Nani, Giorgos Karagounis gets a block in.
-0:00 The referee gets the match started.
+
+
+
+
+
+
+
+
+95:00 Final Score Fulham 0 - 1 Man Utd
+94:59 Full time The referee signals the end of the game.
+90:00 +3:52 Unfair challenge on Mladen Petric by Danny Welbeck results in a free kick. Shot comes in from Hugo Rodallega from the free kick.
+92:07 David De Gea restarts play with the free kick.
+92:07 Booking Wayne Rooney shown a yellow card.
+91:56 Patrice Evra fouled by Damien Duff, the ref awards a free kick.
+90:43 Urby Emanuelson takes a shot. Rio Ferdinand gets a block in. John Arne Riise takes the outswinging corner, Philippe Senderos takes a shot. Robin van Persie makes a clearance.
+89:39 Unfair challenge on Philippe Senderos by Javier Hernandez results in a free kick. Free kick taken by Mark Schwarzer.
+89:04 Mladen Petric gives away a free kick for an unfair challenge on Michael Carrick. Direct free kick taken by David De Gea. 87:53 Bryan Ruiz takes a shot. Wayne Rooney gets a block in. 84:32 Urby Emanuelson challenges Javier Hernandez unfairly and gives away a free kick. Free kick crossed by Ryan Giggs, clearance by Sascha Riether.
+83:09 Mark Schwarzer takes the indirect free kick.
+83:09 Substitution Danny Welbeck is brought on as a substitute for Luis Nani.
+83:09 The offside flag is raised against Robin van Persie.
+80:55 Substitution Mladen Petric on for Ashkan Dejagah. 80:55 Outswinging corner taken left-footed by Damien Duff from the left by-line, Hugo Rodallega has a headed effort at goal from deep inside the area missing to the left of the target.
+78:09 Assist on the goal came from Jonny Evans.
+78:09 Goal - Wayne Rooney - Fulham 0 - 1 Man Utd Wayne Rooney fires in a goal from the edge of the area to the bottom right corner of the goal. Fulham 0-1 Man Utd.
+78:09 The assist for the goal came from Jonny Evans.
+78:09 Goal scored - Wayne Rooney - Fulham 0 - 1 Man Utd Wayne Rooney grabs a goal from the edge of the penalty box to the bottom right corner of the goal. Fulham 0-1 Man Utd.
+76:38 Free kick awarded for a foul by Jonny Evans on Bryan Ruiz. John Arne Riise restarts play with the free kick, Chris Baird produces a right-footed shot from outside the penalty box and misses right.
+75:54 Outswinging corner taken left-footed by Damien Duff, Chris Baird takes a shot. Clearance by Rafael Da Silva.
+74:19 Substitution Ryan Giggs is brought on as a substitute for Tom Cleverley.
+72:19 Header by Ashkan Dejagah from deep inside the penalty area misses to the left of the target.
+70:54 Sascha Riether takes a shot. Save by David De Gea.
+68:58 Inswinging corner taken left-footed by Robin van Persie from the right by-line, clearance by Chris Baird.
+66:47 Free kick crossed right-footed by Luis Nani from right channel, John Arne Riise makes a clearance.
+66:47 Substitution Urby Emanuelson is brought on as a substitute for Giorgos Karagounis.
+66:47 Free kick awarded for an unfair challenge on Robin van Persie by Chris Baird.
+64:44 Shot comes in from Robin van Persie from the free kick, comfortable save by Mark Schwarzer.
+64:44 Substitution Javier Hernandez comes on in place of Antonio Valencia.
+64:44 Booking for Chris Baird.
+64:40 Chris Baird challenges Antonio Valencia unfairly and gives away a free kick.
+63:33 Luis Nani takes a shot. Philippe Senderos gets a block in. Inswinging corner taken by Wayne Rooney from the left by-line, Bryan Ruiz manages to make a clearance.
+62:29 The assistant referee flags for offside against Luis Nani. Indirect free kick taken by Mark Schwarzer.
+62:13 Shot from 25 yards from Chris Baird. Save by David De Gea.
+60:40 Rafael Da Silva concedes a free kick for a foul on Bryan Ruiz. Giorgos Karagounis takes the direct free kick.
+59:51 Hugo Rodallega is ruled offside. Rio Ferdinand restarts play with the free kick.
+57:59 Robin van Persie is ruled offside. Indirect free kick taken by Mark Schwarzer.
+55:47 Effort on goal by Rafael Da Silva from just outside the penalty area goes harmlessly over the target.
+55:08 Giorgos Karagounis produces a right-footed shot from just outside the box that goes wide left of the target.
+52:43 Foul by Antonio Valencia on John Arne Riise, free kick awarded. Direct free kick taken by John Arne Riise.
+51:54 The referee blows for offside against Antonio Valencia. Indirect free kick taken by Mark Schwarzer.
+50:51 The referee penalises Ashkan Dejagah for handball. Wayne Rooney takes the direct free kick.
+49:03 Rafael Da Silva gives away a free kick for an unfair challenge on John Arne Riise. Giorgos Karagounis takes the direct free kick.
+48:37 Robin van Persie takes a shot. Mark Schwarzer makes a save.
+47:12 Ashkan Dejagah is ruled offside. David De Gea takes the free kick.
+46:34 Centre by Antonio Valencia.
+46:01 Robin van Persie challenges Giorgos Karagounis unfairly and gives away a free kick. Chris Baird restarts play with the free kick.
+45:01 The game restarts for the second half.
+45:01 Substitution Aaron Hughes is brought on as a substitute for Brede Hangeland.
+45:00 Half time The half-time whistle blows.
+43:13 Robin van Persie takes a shot. Save by Mark Schwarzer.
+42:07 The ball is delivered by Robin van Persie, John Arne Riise makes a clearance. Corner taken left-footed by Robin van Persie from the right by-line, clearance by Brede Hangeland.
+39:41 Antonio Valencia crosses the ball.
+38:47 Foul by Wayne Rooney on Ashkan Dejagah, free kick awarded. The free kick is swung in left-footed by Damien Duff, Jonny Evans manages to make a clearance.
+37:40 Ashkan Dejagah fouled by Patrice Evra, the ref awards a free kick. Free kick crossed left-footed by Damien Duff from right channel, Jonny Evans makes a clearance.
+33:02 Luis Nani produces a curled right-footed shot from 18 yards. Blocked by Philippe Senderos. Corner taken left-footed by Robin van Persie from the right by-line, clearance made by Brede Hangeland. Jonny Evans challenges Brede Hangeland unfairly and gives away a free kick. Free kick taken by Mark Schwarzer.
+31:52 Wayne Rooney takes a shot.
+29:06 Free kick awarded for an unfair challenge on Ashkan Dejagah by Luis Nani. Free kick taken by Mark Schwarzer.
+27:36 Centre by Damien Duff, clearance by Rio Ferdinand.
+27:02 Inswinging corner taken by Damien Duff from the right by-line, clearance by Robin van Persie.
+24:36 Inswinging corner taken by Wayne Rooney from the left by-line, clearance by Brede Hangeland.
+23:44 Unfair challenge on Bryan Ruiz by Robin van Persie results in a free kick. Free kick taken by Bryan Ruiz.
+21:55 Damien Duff gives away a free kick for an unfair challenge on Tom Cleverley. Robin van Persie delivers the ball from the free kick left-footed from right channel, clearance by Bryan Ruiz.
+20:20 Foul by Luis Nani on Giorgos Karagounis, free kick awarded. Direct free kick taken by Chris Baird.
+19:46 Antonio Valencia crosses the ball, blocked by John Arne Riise.
+18:47 Wayne Rooney produces a right-footed shot from the edge of the area and misses to the left of the target.
+18:36 Brede Hangeland gives away a free kick for an unfair challenge on Luis Nani. Patrice Evra takes the free kick.
+15:05 Antonio Valencia produces a right-footed shot from deep inside the penalty box which goes wide of the right-hand upright.
+17:27 The assistant referee signals for offside against Robin van Persie. Mark Schwarzer takes the free kick.
+17:04 Ashkan Dejagah produces a right-footed shot from the edge of the box and misses to the right of the target.
+16:32 Bryan Ruiz fouled by Patrice Evra, the ref awards a free kick. The free kick is delivered left-footed by Bryan Ruiz from right wing, Rio Ferdinand makes a clearance.
+15:05 Effort from inside the area by Luis Nani misses to the right of the target.
+14:52 Corner taken right-footed by Wayne Rooney from the left by-line, Brede Hangeland manages to make a clearance.
+14:19 Bryan Ruiz takes a shot.
+13:51 Centre by Luis Nani, clearance made by Philippe Senderos.
+12:09 The assistant referee signals for offside against Antonio Valencia. Mark Schwarzer takes the indirect free kick.
+11:14 John Arne Riise has a drilled shot. Save by David De Gea. Inswinging corner taken left-footed by Damien Duff, save by David De Gea.
+10:21 Rafael Da Silva sends in a cross, blocked by Brede Hangeland.
+7:17 Inswinging corner taken left-footed by Robin van Persie from the right by-line, Patrice Evra takes a shot. Patrice Evra takes a shot. Save by Mark Schwarzer.
+7:03 The ball is sent over by Wayne Rooney.
+6:16 Luis Nani takes a shot. Blocked by Sascha Riether. Inswinging corner taken by Wayne Rooney, Mark Schwarzer makes a save.
+5:25 Bryan Ruiz concedes a free kick for a foul on Patrice Evra. David De Gea takes the free kick.
+4:53 The ball is delivered by Rafael Da Silva, save by Mark Schwarzer.
+4:00 Ashkan Dejagah takes a shot.
+1:24 Free kick awarded for an unfair challenge on Giorgos Karagounis by Tom Cleverley. Philippe Senderos takes the free kick.
+0:45 A cross is delivered by Luis Nani, Giorgos Karagounis gets a block in.
+0:00 The referee gets the match started.
+
+
+
-
-
-
-
-
-
-
-Arsenal vs Stoke City
-
-95:22 Final Score Arsenal 1 - 0 Stoke
-95:21 Full time The referee blows his whistle to end the game.
-94:06 Unfair challenge on Laurent Koscielny by Kenwyne Jones results in a free kick. Wojciech Szczesny takes the free kick.
-92:40 Michael Owen gives away a free kick for an unfair challenge on Mikel Arteta. Direct free kick taken by Mikel Arteta.
-89:58 Laurent Koscielny restarts play with the free kick.
-89:58 Substitution Theo Walcott goes off and Aaron Ramsey comes on.
-89:58 Nacho Monreal fouled by Cameron Jerome, the ref awards a free kick.
-88:10 Mikel Arteta restarts play with the free kick.
-88:10 Booking Ryan Shawcross is given a yellow card.
-88:04 Free kick awarded for a foul by Ryan Shawcross on Laurent Koscielny.
-82:39 Ryan Shawcross takes the free kick.
-82:39 Substitution (Stoke) makes a substitution, with Michael Owen coming on for Geoff Cameron.
-82:39 Substitution Jonathan Walters goes off and Cameron Jerome comes on.
-82:39 Substitution Kenwyne Jones is brought on as a substitute for Peter Crouch.
-82:39 Laurent Koscielny challenges Peter Crouch unfairly and gives away a free kick.
-80:50 Jack Wilshere takes the inswinging corner, Ryan Shawcross manages to make a clearance.
-79:48 Santi Cazorla takes a shot. Save by Asmir Begovic. Theo Walcott decides to take a short corner.
-79:41 Santi Cazorla takes a shot. Blocked by Ryan Shawcross. Santi Cazorla takes a shot. Blocked by Ryan Shawcross.
-77:11 Assist on the goal came from Theo Walcott.
-77:11 Goal scored. Goal - Lukas Podolski - Arsenal 1 - 0 Stoke Lukas Podolski grabs a goal direct from the free kick from just outside the area low into the middle of the goal. Arsenal 1-0 Stoke.
-76:14 Booking Andy Wilkinson is given a yellow card.
-75:57 Unfair challenge on Theo Walcott by Andy Wilkinson results in a free kick.
-74:12 The assistant referee signals for offside against Peter Crouch. Laurent Koscielny restarts play with the free kick.
-73:27 Shot from long distance by Nacho Monreal misses to the right of the goal.
-71:38 Headed effort from deep inside the area by Olivier Giroud misses to the right of the goal.
-69:42 Direct free kick taken by Jack Wilshere.
-69:42 Booking Glenn Whelan booked for unsporting behaviour.
-69:32 Santi Cazorla fouled by Glenn Whelan, the ref awards a free kick.
-68:46 Bacary Sagna challenges Matthew Etherington unfairly and gives away a free kick. Free kick crossed left-footed by Matthew Etherington from left wing, clearance made by Per Mertesacker.
-67:22 Substitution Santi Cazorla replaces Vassiriki Diaby.
-67:22 Substitution Lukas Podolski comes on in place of Alex Oxlade-Chamberlain.
-63:48 Ryan Shawcross has an effort at goal from just outside the area which goes wide of the left-hand post.
-61:09 Geoff Cameron is caught offside. Laurent Koscielny takes the indirect free kick.
-55:18 Effort on goal by Olivier Giroud from deep inside the area goes harmlessly over the bar.
-51:04 Ryan Shotton concedes a free kick for a foul on Alex Oxlade-Chamberlain. Jack Wilshere takes the free kick.
-50:20 Free kick awarded for an unfair challenge on Jack Wilshere by Robert Huth. Mikel Arteta takes the direct free kick.
-48:59 Inswinging corner taken by Theo Walcott, Asmir Begovic makes a save.
-46:45 Unfair challenge on Mikel Arteta by Peter Crouch results in a free kick. Mikel Arteta takes the free kick. 45:01 The referee gets the second half underway.
-48:23 Half time
-40:01 Alex Oxlade-Chamberlain takes a shot. Save made by Asmir Begovic. Corner from the right by-line taken by Jack Wilshere, clearance made by Steven Nzonzi. Inswinging corner taken right-footed by Theo Walcott from the left by-line, clearance by Peter Crouch.
-38:25 Olivier Giroud is caught offside. Asmir Begovic restarts play with the free kick.
-34:31 Laurent Koscielny takes a shot. Asmir Begovic makes a save.
-33:58 Inswinging corner taken by Theo Walcott from the left by-line, Peter Crouch manages to make a clearance.
-30:39 Corner taken by Jack Wilshere from the right by-line, Alex Oxlade-Chamberlain takes a shot. Save by Asmir Begovic. Inswinging corner taken by Theo Walcott, Peter Crouch makes a clearance.
-29:36 Unfair challenge on Olivier Giroud by Ryan Shawcross results in a free kick. Free kick taken by Mikel Arteta.
-29:04 Effort on goal by Ryan Shawcross from just outside the area goes harmlessly over the target.
-25:37 Theo Walcott takes a shot. Blocked by Andy Wilkinson. Foul by Mikel Arteta on Geoff Cameron, free kick awarded. Free kick taken by Asmir Begovic.
-22:35 Corner from the right by-line taken by Jack Wilshere, save made by Asmir Begovic.
-21:50 Shot from just outside the box by Glenn Whelan goes over the bar.
-20:51 Alex Oxlade-Chamberlain takes a shot. Ryan Shawcross gets a block in. Olivier Giroud is caught offside. Asmir Begovic takes the free kick.
-17:04 Headed effort from the edge of the area by Ryan Shawcross goes wide of the right-hand post. Free kick awarded for an unfair challenge on Theo Walcott by Andy Wilkinson. Jack Wilshere crosses the ball from the free kick left-footed from right wing, Robert Huth manages to make a clearance.
-16:33 Peter Crouch takes a shot. Laurent Koscielny gets a block in. Inswinging corner taken by Matthew Etherington.
-14:38 Olivier Giroud produces a headed effort from deep inside the six-yard box which goes wide of the right-hand upright.
-13:49 Jonathan Walters takes a shot. Wojciech Szczesny makes a save.
-12:29 Free kick awarded for an unfair challenge on Theo Walcott by Matthew Etherington. Bacary Sagna takes the free kick.
-6:15 Corner from the right by-line taken by Jack Wilshere, Geoff Cameron manages to make a clearance. Inswinging corner taken left-footed by Jack Wilshere played to the near post, Glenn Whelan manages to make a clearance.
-4:57 Jack Wilshere takes a shot from inside the box clearing the bar.
-1:57 Effort from the edge of the area by Alex Oxlade-Chamberlain goes wide of the left-hand upright.
-1:06 Free kick awarded for an unfair challenge on Jack Wilshere by Geoff Cameron. Mikel Arteta restarts play with the free kick.
-0:00 The match has kicked off.
\ No newline at end of file
+
+
+
+
+95:22 Final Score Arsenal 1 - 0 Stoke
+95:21 Full time The referee blows his whistle to end the game.
+94:06 Unfair challenge on Laurent Koscielny by Kenwyne Jones results in a free kick. Wojciech Szczesny takes the free kick.
+92:40 Michael Owen gives away a free kick for an unfair challenge on Mikel Arteta. Direct free kick taken by Mikel Arteta.
+89:58 Laurent Koscielny restarts play with the free kick.
+89:58 Substitution Theo Walcott goes off and Aaron Ramsey comes on.
+89:58 Nacho Monreal fouled by Cameron Jerome, the ref awards a free kick.
+88:10 Mikel Arteta restarts play with the free kick.
+88:10 Booking Ryan Shawcross is given a yellow card.
+88:04 Free kick awarded for a foul by Ryan Shawcross on Laurent Koscielny.
+82:39 Ryan Shawcross takes the free kick.
+82:39 Substitution (Stoke) makes a substitution, with Michael Owen coming on for Geoff Cameron.
+82:39 Substitution Jonathan Walters goes off and Cameron Jerome comes on.
+82:39 Substitution Kenwyne Jones is brought on as a substitute for Peter Crouch.
+82:39 Laurent Koscielny challenges Peter Crouch unfairly and gives away a free kick.
+80:50 Jack Wilshere takes the inswinging corner, Ryan Shawcross manages to make a clearance.
+79:48 Santi Cazorla takes a shot. Save by Asmir Begovic. Theo Walcott decides to take a short corner.
+79:41 Santi Cazorla takes a shot. Blocked by Ryan Shawcross. Santi Cazorla takes a shot. Blocked by Ryan Shawcross.
+77:11 Assist on the goal came from Theo Walcott.
+77:11 Goal scored. Goal - Lukas Podolski - Arsenal 1 - 0 Stoke Lukas Podolski grabs a goal direct from the free kick from just outside the area low into the middle of the goal. Arsenal 1-0 Stoke.
+76:14 Booking Andy Wilkinson is given a yellow card.
+75:57 Unfair challenge on Theo Walcott by Andy Wilkinson results in a free kick.
+74:12 The assistant referee signals for offside against Peter Crouch. Laurent Koscielny restarts play with the free kick.
+73:27 Shot from long distance by Nacho Monreal misses to the right of the goal.
+71:38 Headed effort from deep inside the area by Olivier Giroud misses to the right of the goal.
+69:42 Direct free kick taken by Jack Wilshere.
+69:42 Booking Glenn Whelan booked for unsporting behaviour.
+69:32 Santi Cazorla fouled by Glenn Whelan, the ref awards a free kick.
+68:46 Bacary Sagna challenges Matthew Etherington unfairly and gives away a free kick. Free kick crossed left-footed by Matthew Etherington from left wing, clearance made by Per Mertesacker.
+67:22 Substitution Santi Cazorla replaces Vassiriki Diaby.
+67:22 Substitution Lukas Podolski comes on in place of Alex Oxlade-Chamberlain.
+63:48 Ryan Shawcross has an effort at goal from just outside the area which goes wide of the left-hand post.
+61:09 Geoff Cameron is caught offside. Laurent Koscielny takes the indirect free kick.
+55:18 Effort on goal by Olivier Giroud from deep inside the area goes harmlessly over the bar.
+51:04 Ryan Shotton concedes a free kick for a foul on Alex Oxlade-Chamberlain. Jack Wilshere takes the free kick.
+50:20 Free kick awarded for an unfair challenge on Jack Wilshere by Robert Huth. Mikel Arteta takes the direct free kick.
+48:59 Inswinging corner taken by Theo Walcott, Asmir Begovic makes a save.
+46:45 Unfair challenge on Mikel Arteta by Peter Crouch results in a free kick. Mikel Arteta takes the free kick. 45:01 The referee gets the second half underway.
+48:23 Half time
+40:01 Alex Oxlade-Chamberlain takes a shot. Save made by Asmir Begovic. Corner from the right by-line taken by Jack Wilshere, clearance made by Steven Nzonzi. Inswinging corner taken right-footed by Theo Walcott from the left by-line, clearance by Peter Crouch.
+38:25 Olivier Giroud is caught offside. Asmir Begovic restarts play with the free kick.
+34:31 Laurent Koscielny takes a shot. Asmir Begovic makes a save.
+33:58 Inswinging corner taken by Theo Walcott from the left by-line, Peter Crouch manages to make a clearance.
+30:39 Corner taken by Jack Wilshere from the right by-line, Alex Oxlade-Chamberlain takes a shot. Save by Asmir Begovic. Inswinging corner taken by Theo Walcott, Peter Crouch makes a clearance.
+29:36 Unfair challenge on Olivier Giroud by Ryan Shawcross results in a free kick. Free kick taken by Mikel Arteta.
+29:04 Effort on goal by Ryan Shawcross from just outside the area goes harmlessly over the target.
+25:37 Theo Walcott takes a shot. Blocked by Andy Wilkinson. Foul by Mikel Arteta on Geoff Cameron, free kick awarded. Free kick taken by Asmir Begovic.
+22:35 Corner from the right by-line taken by Jack Wilshere, save made by Asmir Begovic.
+21:50 Shot from just outside the box by Glenn Whelan goes over the bar.
+20:51 Alex Oxlade-Chamberlain takes a shot. Ryan Shawcross gets a block in. Olivier Giroud is caught offside. Asmir Begovic takes the free kick.
+17:04 Headed effort from the edge of the area by Ryan Shawcross goes wide of the right-hand post. Free kick awarded for an unfair challenge on Theo Walcott by Andy Wilkinson. Jack Wilshere crosses the ball from the free kick left-footed from right wing, Robert Huth manages to make a clearance.
+16:33 Peter Crouch takes a shot. Laurent Koscielny gets a block in. Inswinging corner taken by Matthew Etherington.
+14:38 Olivier Giroud produces a headed effort from deep inside the six-yard box which goes wide of the right-hand upright.
+13:49 Jonathan Walters takes a shot. Wojciech Szczesny makes a save.
+12:29 Free kick awarded for an unfair challenge on Theo Walcott by Matthew Etherington. Bacary Sagna takes the free kick.
+6:15 Corner from the right by-line taken by Jack Wilshere, Geoff Cameron manages to make a clearance. Inswinging corner taken left-footed by Jack Wilshere played to the near post, Glenn Whelan manages to make a clearance.
+4:57 Jack Wilshere takes a shot from inside the box clearing the bar.
+1:57 Effort from the edge of the area by Alex Oxlade-Chamberlain goes wide of the left-hand upright.
+1:06 Free kick awarded for an unfair challenge on Jack Wilshere by Geoff Cameron. Mikel Arteta restarts play with the free kick.
+0:00 The match has kicked off.
+
+
+
+
+
+
+
+
From f6019e4cd50926bd2d45ec1a65fe8bdd9d7cc0e6 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Thu, 7 Feb 2013 21:42:10 +0000
Subject: [PATCH 016/142] Added .gitignore
---
producer-consumer/.gitignore | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 producer-consumer/.gitignore
diff --git a/producer-consumer/.gitignore b/producer-consumer/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/producer-consumer/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
From dde25cf23e8b2c7d444d99487f02c972076f7efc Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Thu, 7 Feb 2013 22:09:33 +0000
Subject: [PATCH 017/142] Added .gitignore again
---
unit-testing-threads/.gitignore | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 unit-testing-threads/.gitignore
diff --git a/unit-testing-threads/.gitignore b/unit-testing-threads/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/unit-testing-threads/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
From a69314b1a9a7056ef9c93ac789c3d4b5c22c2dc5 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Thu, 7 Feb 2013 22:17:42 +0000
Subject: [PATCH 018/142] Added producer-consumer to build-all
---
build-all/pom.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/build-all/pom.xml b/build-all/pom.xml
index 03b9032..d8e0131 100644
--- a/build-all/pom.xml
+++ b/build-all/pom.xml
@@ -23,5 +23,6 @@
../deadlocks../spring-security/tomcat-ssl../unit-testing-threads
+ ../producer-consumer
\ No newline at end of file
From c0de71d8f5861916b62d5a3923818eb864dc5889 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Thu, 7 Feb 2013 22:28:27 +0000
Subject: [PATCH 019/142] Bit of an update to the MatchReporter
---
.../com/captaindebug/producerconsumer/MatchReporter.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/producer-consumer/src/main/java/com/captaindebug/producerconsumer/MatchReporter.java b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/MatchReporter.java
index 3b9f167..01e6872 100644
--- a/producer-consumer/src/main/java/com/captaindebug/producerconsumer/MatchReporter.java
+++ b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/MatchReporter.java
@@ -1,5 +1,13 @@
package com.captaindebug.producerconsumer;
+import java.util.Queue;
+
public class MatchReporter {
+ private final Match match;
+
+ public MatchReporter(Match theBigMatch, Queue queue) {
+ this.match = theBigMatch;
+ }
+
}
From 05d67d18cbb50eab34e0c8f989a6412079b8412b Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sat, 9 Feb 2013 20:35:09 +0000
Subject: [PATCH 020/142] Lost of produce/consumer work done, but not
complete...
---
producer-consumer/pom.xml | 8 ++
.../captaindebug/producerconsumer/Main.java | 9 ++
.../captaindebug/producerconsumer/Match.java | 24 ++--
.../producerconsumer/MatchReporter.java | 47 +++++++-
.../producerconsumer/Message.java | 42 ++++---
.../producerconsumer/PrintHead.java | 18 +++
.../producerconsumer/Teletype.java | 39 ++++++-
.../src/main/resources/context.xml | 27 +++++
.../producerconsumer/MatchReporterTest.java | 108 ++++++++++++++++++
.../producerconsumer/MatchTest.java | 22 +++-
.../producerconsumer/TeletypeTest.java | 55 +++++++++
11 files changed, 363 insertions(+), 36 deletions(-)
create mode 100644 producer-consumer/src/main/java/com/captaindebug/producerconsumer/PrintHead.java
create mode 100644 producer-consumer/src/main/resources/context.xml
create mode 100644 producer-consumer/src/test/java/com/captaindebug/producerconsumer/MatchReporterTest.java
create mode 100644 producer-consumer/src/test/java/com/captaindebug/producerconsumer/TeletypeTest.java
diff --git a/producer-consumer/pom.xml b/producer-consumer/pom.xml
index b902808..3cfc75a 100644
--- a/producer-consumer/pom.xml
+++ b/producer-consumer/pom.xml
@@ -9,6 +9,8 @@
Example Producer Consumer Pattern1.6.1
+ 3.0.5.RELEASE
+
+
+
+
+
+
+
+
+95:30 END OF FILE
+95:00 Final Score Fulham 0 - 1 Man Utd
+94:59 Full time The referee signals the end of the game.
+90:00 +3:52 Unfair challenge on Mladen Petric by Danny Welbeck results in a free kick. Shot comes in from Hugo Rodallega from the free kick.
+92:07 David De Gea restarts play with the free kick.
+92:07 Booking Wayne Rooney shown a yellow card.
+91:56 Patrice Evra fouled by Damien Duff, the ref awards a free kick.
+90:43 Urby Emanuelson takes a shot. Rio Ferdinand gets a block in. John Arne Riise takes the outswinging corner, Philippe Senderos takes a shot. Robin van Persie makes a clearance.
+89:39 Unfair challenge on Philippe Senderos by Javier Hernandez results in a free kick. Free kick taken by Mark Schwarzer.
+89:04 Mladen Petric gives away a free kick for an unfair challenge on Michael Carrick. Direct free kick taken by David De Gea. 87:53 Bryan Ruiz takes a shot. Wayne Rooney gets a block in. 84:32 Urby Emanuelson challenges Javier Hernandez unfairly and gives away a free kick. Free kick crossed by Ryan Giggs, clearance by Sascha Riether.
+83:09 Mark Schwarzer takes the indirect free kick.
+83:09 Substitution Danny Welbeck is brought on as a substitute for Luis Nani.
+83:09 The offside flag is raised against Robin van Persie.
+80:55 Substitution Mladen Petric on for Ashkan Dejagah. 80:55 Outswinging corner taken left-footed by Damien Duff from the left by-line, Hugo Rodallega has a headed effort at goal from deep inside the area missing to the left of the target.
+78:09 Assist on the goal came from Jonny Evans.
+78:09 Goal - Wayne Rooney - Fulham 0 - 1 Man Utd Wayne Rooney fires in a goal from the edge of the area to the bottom right corner of the goal. Fulham 0-1 Man Utd.
+78:09 The assist for the goal came from Jonny Evans.
+78:09 Goal scored - Wayne Rooney - Fulham 0 - 1 Man Utd Wayne Rooney grabs a goal from the edge of the penalty box to the bottom right corner of the goal. Fulham 0-1 Man Utd.
+76:38 Free kick awarded for a foul by Jonny Evans on Bryan Ruiz. John Arne Riise restarts play with the free kick, Chris Baird produces a right-footed shot from outside the penalty box and misses right.
+75:54 Outswinging corner taken left-footed by Damien Duff, Chris Baird takes a shot. Clearance by Rafael Da Silva.
+74:19 Substitution Ryan Giggs is brought on as a substitute for Tom Cleverley.
+72:19 Header by Ashkan Dejagah from deep inside the penalty area misses to the left of the target.
+70:54 Sascha Riether takes a shot. Save by David De Gea.
+68:58 Inswinging corner taken left-footed by Robin van Persie from the right by-line, clearance by Chris Baird.
+66:47 Free kick crossed right-footed by Luis Nani from right channel, John Arne Riise makes a clearance.
+66:47 Substitution Urby Emanuelson is brought on as a substitute for Giorgos Karagounis.
+66:47 Free kick awarded for an unfair challenge on Robin van Persie by Chris Baird.
+64:44 Shot comes in from Robin van Persie from the free kick, comfortable save by Mark Schwarzer.
+64:44 Substitution Javier Hernandez comes on in place of Antonio Valencia.
+64:44 Booking for Chris Baird.
+64:40 Chris Baird challenges Antonio Valencia unfairly and gives away a free kick.
+63:33 Luis Nani takes a shot. Philippe Senderos gets a block in. Inswinging corner taken by Wayne Rooney from the left by-line, Bryan Ruiz manages to make a clearance.
+62:29 The assistant referee flags for offside against Luis Nani. Indirect free kick taken by Mark Schwarzer.
+62:13 Shot from 25 yards from Chris Baird. Save by David De Gea.
+60:40 Rafael Da Silva concedes a free kick for a foul on Bryan Ruiz. Giorgos Karagounis takes the direct free kick.
+59:51 Hugo Rodallega is ruled offside. Rio Ferdinand restarts play with the free kick.
+57:59 Robin van Persie is ruled offside. Indirect free kick taken by Mark Schwarzer.
+55:47 Effort on goal by Rafael Da Silva from just outside the penalty area goes harmlessly over the target.
+55:08 Giorgos Karagounis produces a right-footed shot from just outside the box that goes wide left of the target.
+52:43 Foul by Antonio Valencia on John Arne Riise, free kick awarded. Direct free kick taken by John Arne Riise.
+51:54 The referee blows for offside against Antonio Valencia. Indirect free kick taken by Mark Schwarzer.
+50:51 The referee penalises Ashkan Dejagah for handball. Wayne Rooney takes the direct free kick.
+49:03 Rafael Da Silva gives away a free kick for an unfair challenge on John Arne Riise. Giorgos Karagounis takes the direct free kick.
+48:37 Robin van Persie takes a shot. Mark Schwarzer makes a save.
+47:12 Ashkan Dejagah is ruled offside. David De Gea takes the free kick.
+46:34 Centre by Antonio Valencia.
+46:01 Robin van Persie challenges Giorgos Karagounis unfairly and gives away a free kick. Chris Baird restarts play with the free kick.
+45:01 The game restarts for the second half.
+45:01 Substitution Aaron Hughes is brought on as a substitute for Brede Hangeland.
+45:00 Half time The half-time whistle blows.
+43:13 Robin van Persie takes a shot. Save by Mark Schwarzer.
+42:07 The ball is delivered by Robin van Persie, John Arne Riise makes a clearance. Corner taken left-footed by Robin van Persie from the right by-line, clearance by Brede Hangeland.
+39:41 Antonio Valencia crosses the ball.
+38:47 Foul by Wayne Rooney on Ashkan Dejagah, free kick awarded. The free kick is swung in left-footed by Damien Duff, Jonny Evans manages to make a clearance.
+37:40 Ashkan Dejagah fouled by Patrice Evra, the ref awards a free kick. Free kick crossed left-footed by Damien Duff from right channel, Jonny Evans makes a clearance.
+33:02 Luis Nani produces a curled right-footed shot from 18 yards. Blocked by Philippe Senderos. Corner taken left-footed by Robin van Persie from the right by-line, clearance made by Brede Hangeland. Jonny Evans challenges Brede Hangeland unfairly and gives away a free kick. Free kick taken by Mark Schwarzer.
+31:52 Wayne Rooney takes a shot.
+29:06 Free kick awarded for an unfair challenge on Ashkan Dejagah by Luis Nani. Free kick taken by Mark Schwarzer.
+27:36 Centre by Damien Duff, clearance by Rio Ferdinand.
+27:02 Inswinging corner taken by Damien Duff from the right by-line, clearance by Robin van Persie.
+24:36 Inswinging corner taken by Wayne Rooney from the left by-line, clearance by Brede Hangeland.
+23:44 Unfair challenge on Bryan Ruiz by Robin van Persie results in a free kick. Free kick taken by Bryan Ruiz.
+21:55 Damien Duff gives away a free kick for an unfair challenge on Tom Cleverley. Robin van Persie delivers the ball from the free kick left-footed from right channel, clearance by Bryan Ruiz.
+20:20 Foul by Luis Nani on Giorgos Karagounis, free kick awarded. Direct free kick taken by Chris Baird.
+19:46 Antonio Valencia crosses the ball, blocked by John Arne Riise.
+18:47 Wayne Rooney produces a right-footed shot from the edge of the area and misses to the left of the target.
+18:36 Brede Hangeland gives away a free kick for an unfair challenge on Luis Nani. Patrice Evra takes the free kick.
+15:05 Antonio Valencia produces a right-footed shot from deep inside the penalty box which goes wide of the right-hand upright.
+17:27 The assistant referee signals for offside against Robin van Persie. Mark Schwarzer takes the free kick.
+17:04 Ashkan Dejagah produces a right-footed shot from the edge of the box and misses to the right of the target.
+16:32 Bryan Ruiz fouled by Patrice Evra, the ref awards a free kick. The free kick is delivered left-footed by Bryan Ruiz from right wing, Rio Ferdinand makes a clearance.
+15:05 Effort from inside the area by Luis Nani misses to the right of the target.
+14:52 Corner taken right-footed by Wayne Rooney from the left by-line, Brede Hangeland manages to make a clearance.
+14:19 Bryan Ruiz takes a shot.
+13:51 Centre by Luis Nani, clearance made by Philippe Senderos.
+12:09 The assistant referee signals for offside against Antonio Valencia. Mark Schwarzer takes the indirect free kick.
+11:14 John Arne Riise has a drilled shot. Save by David De Gea. Inswinging corner taken left-footed by Damien Duff, save by David De Gea.
+10:21 Rafael Da Silva sends in a cross, blocked by Brede Hangeland.
+7:17 Inswinging corner taken left-footed by Robin van Persie from the right by-line, Patrice Evra takes a shot. Patrice Evra takes a shot. Save by Mark Schwarzer.
+7:03 The ball is sent over by Wayne Rooney.
+6:16 Luis Nani takes a shot. Blocked by Sascha Riether. Inswinging corner taken by Wayne Rooney, Mark Schwarzer makes a save.
+5:25 Bryan Ruiz concedes a free kick for a foul on Patrice Evra. David De Gea takes the free kick.
+4:53 The ball is delivered by Rafael Da Silva, save by Mark Schwarzer.
+4:00 Ashkan Dejagah takes a shot.
+1:24 Free kick awarded for an unfair challenge on Giorgos Karagounis by Tom Cleverley. Philippe Senderos takes the free kick.
+0:45 A cross is delivered by Luis Nani, Giorgos Karagounis gets a block in.
+0:00 The referee gets the match started.
+
+
+
+
+
+
+
+
+95:40 END OF FILE
+95:22 Final Score Arsenal 1 - 0 Stoke
+95:21 Full time The referee blows his whistle to end the game.
+94:06 Unfair challenge on Laurent Koscielny by Kenwyne Jones results in a free kick. Wojciech Szczesny takes the free kick.
+92:40 Michael Owen gives away a free kick for an unfair challenge on Mikel Arteta. Direct free kick taken by Mikel Arteta.
+89:58 Laurent Koscielny restarts play with the free kick.
+89:58 Substitution Theo Walcott goes off and Aaron Ramsey comes on.
+89:58 Nacho Monreal fouled by Cameron Jerome, the ref awards a free kick.
+88:10 Mikel Arteta restarts play with the free kick.
+88:10 Booking Ryan Shawcross is given a yellow card.
+88:04 Free kick awarded for a foul by Ryan Shawcross on Laurent Koscielny.
+82:39 Ryan Shawcross takes the free kick.
+82:39 Substitution (Stoke) makes a substitution, with Michael Owen coming on for Geoff Cameron.
+82:39 Substitution Jonathan Walters goes off and Cameron Jerome comes on.
+82:39 Substitution Kenwyne Jones is brought on as a substitute for Peter Crouch.
+82:39 Laurent Koscielny challenges Peter Crouch unfairly and gives away a free kick.
+80:50 Jack Wilshere takes the inswinging corner, Ryan Shawcross manages to make a clearance.
+79:48 Santi Cazorla takes a shot. Save by Asmir Begovic. Theo Walcott decides to take a short corner.
+79:41 Santi Cazorla takes a shot. Blocked by Ryan Shawcross. Santi Cazorla takes a shot. Blocked by Ryan Shawcross.
+77:11 Assist on the goal came from Theo Walcott.
+77:11 Goal scored. Goal - Lukas Podolski - Arsenal 1 - 0 Stoke Lukas Podolski grabs a goal direct from the free kick from just outside the area low into the middle of the goal. Arsenal 1-0 Stoke.
+76:14 Booking Andy Wilkinson is given a yellow card.
+75:57 Unfair challenge on Theo Walcott by Andy Wilkinson results in a free kick.
+74:12 The assistant referee signals for offside against Peter Crouch. Laurent Koscielny restarts play with the free kick.
+73:27 Shot from long distance by Nacho Monreal misses to the right of the goal.
+71:38 Headed effort from deep inside the area by Olivier Giroud misses to the right of the goal.
+69:42 Direct free kick taken by Jack Wilshere.
+69:42 Booking Glenn Whelan booked for unsporting behaviour.
+69:32 Santi Cazorla fouled by Glenn Whelan, the ref awards a free kick.
+68:46 Bacary Sagna challenges Matthew Etherington unfairly and gives away a free kick. Free kick crossed left-footed by Matthew Etherington from left wing, clearance made by Per Mertesacker.
+67:22 Substitution Santi Cazorla replaces Vassiriki Diaby.
+67:22 Substitution Lukas Podolski comes on in place of Alex Oxlade-Chamberlain.
+63:48 Ryan Shawcross has an effort at goal from just outside the area which goes wide of the left-hand post.
+61:09 Geoff Cameron is caught offside. Laurent Koscielny takes the indirect free kick.
+55:18 Effort on goal by Olivier Giroud from deep inside the area goes harmlessly over the bar.
+51:04 Ryan Shotton concedes a free kick for a foul on Alex Oxlade-Chamberlain. Jack Wilshere takes the free kick.
+50:20 Free kick awarded for an unfair challenge on Jack Wilshere by Robert Huth. Mikel Arteta takes the direct free kick.
+48:59 Inswinging corner taken by Theo Walcott, Asmir Begovic makes a save.
+46:45 Unfair challenge on Mikel Arteta by Peter Crouch results in a free kick. Mikel Arteta takes the free kick. 45:01 The referee gets the second half underway.
+48:23 Half time
+40:01 Alex Oxlade-Chamberlain takes a shot. Save made by Asmir Begovic. Corner from the right by-line taken by Jack Wilshere, clearance made by Steven Nzonzi. Inswinging corner taken right-footed by Theo Walcott from the left by-line, clearance by Peter Crouch.
+38:25 Olivier Giroud is caught offside. Asmir Begovic restarts play with the free kick.
+34:31 Laurent Koscielny takes a shot. Asmir Begovic makes a save.
+33:58 Inswinging corner taken by Theo Walcott from the left by-line, Peter Crouch manages to make a clearance.
+30:39 Corner taken by Jack Wilshere from the right by-line, Alex Oxlade-Chamberlain takes a shot. Save by Asmir Begovic. Inswinging corner taken by Theo Walcott, Peter Crouch makes a clearance.
+29:36 Unfair challenge on Olivier Giroud by Ryan Shawcross results in a free kick. Free kick taken by Mikel Arteta.
+29:04 Effort on goal by Ryan Shawcross from just outside the area goes harmlessly over the target.
+25:37 Theo Walcott takes a shot. Blocked by Andy Wilkinson. Foul by Mikel Arteta on Geoff Cameron, free kick awarded. Free kick taken by Asmir Begovic.
+22:35 Corner from the right by-line taken by Jack Wilshere, save made by Asmir Begovic.
+21:50 Shot from just outside the box by Glenn Whelan goes over the bar.
+20:51 Alex Oxlade-Chamberlain takes a shot. Ryan Shawcross gets a block in. Olivier Giroud is caught offside. Asmir Begovic takes the free kick.
+17:04 Headed effort from the edge of the area by Ryan Shawcross goes wide of the right-hand post. Free kick awarded for an unfair challenge on Theo Walcott by Andy Wilkinson. Jack Wilshere crosses the ball from the free kick left-footed from right wing, Robert Huth manages to make a clearance.
+16:33 Peter Crouch takes a shot. Laurent Koscielny gets a block in. Inswinging corner taken by Matthew Etherington.
+14:38 Olivier Giroud produces a headed effort from deep inside the six-yard box which goes wide of the right-hand upright.
+13:49 Jonathan Walters takes a shot. Wojciech Szczesny makes a save.
+12:29 Free kick awarded for an unfair challenge on Theo Walcott by Matthew Etherington. Bacary Sagna takes the free kick.
+6:15 Corner from the right by-line taken by Jack Wilshere, Geoff Cameron manages to make a clearance. Inswinging corner taken left-footed by Jack Wilshere played to the near post, Glenn Whelan manages to make a clearance.
+4:57 Jack Wilshere takes a shot from inside the box clearing the bar.
+1:57 Effort from the edge of the area by Alex Oxlade-Chamberlain goes wide of the left-hand upright.
+1:06 Free kick awarded for an unfair challenge on Jack Wilshere by Geoff Cameron. Mikel Arteta restarts play with the free kick.
+0:00 The match has kicked off.
+
+
+
+
+
+
+
+
diff --git a/producer-consumer/src/test/java/com/captaindebug/producerconsumer/interruptible/TeletypeTest.java b/producer-consumer/src/test/java/com/captaindebug/producerconsumer/interruptible/TeletypeTest.java
new file mode 100644
index 0000000..b353521
--- /dev/null
+++ b/producer-consumer/src/test/java/com/captaindebug/producerconsumer/interruptible/TeletypeTest.java
@@ -0,0 +1,87 @@
+/**
+ * Copyright 2013 Marin Solutions
+ */
+package com.captaindebug.producerconsumer.interruptible;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.captaindebug.producerconsumer.Message;
+import com.captaindebug.producerconsumer.PrintHead;
+
+/**
+ *
+ * TODO This will be part of another blog....
+ *
+ * @author Roger
+ *
+ */
+public class TeletypeTest {
+
+ private BlockingQueue queue;
+ private Teletype instance;
+ private PrintHead printhead;
+
+ @Before
+ public void setUp() throws Exception {
+
+ printhead = mock(PrintHead.class);
+ queue = new LinkedBlockingQueue();
+ instance = new Teletype(printhead, queue);
+ }
+
+ @Test
+ public void testTeletype_with_two_messages_in_queue() throws InterruptedException {
+
+ int numMessages = initializeQueueWithMessages();
+
+ instance.start();
+
+ synchWithTestInstanceThread(numMessages);
+
+ instance.destroy();
+
+ // assert that we didn't time out.
+ assertEquals(numMessages, instance.getMessageCount());
+ verify(printhead, atLeastOnce()).print(anyString());
+ }
+
+ private int initializeQueueWithMessages() {
+ List messages = getTestMessages();
+ queue.addAll(messages);
+ int numMessages = messages.size();
+ return numMessages;
+ }
+
+ private List getTestMessages() {
+
+ List messages = new ArrayList();
+ Message message = new Message("name", 1L, "String messageText", "String matchTime");
+ messages.add(message);
+ message = new Message("name", 2L, "String messageText", "String matchTime");
+ messages.add(message);
+
+ return messages;
+ }
+
+ private void synchWithTestInstanceThread(int numMessages) throws InterruptedException {
+
+ // Synchronize on the number of messages
+ // This will wait for 1/2 a second at most and then timeout
+ for (int i = 0; (i < 5) && (instance.getMessageCount() < numMessages); i++) {
+
+ Thread.sleep(100);
+ }
+ }
+}
diff --git a/producer-consumer/src/test/java/com/captaindebug/producerconsumer/poisonpill/TeletypeTest.java b/producer-consumer/src/test/java/com/captaindebug/producerconsumer/poisonpill/TeletypeTest.java
new file mode 100644
index 0000000..9eb3494
--- /dev/null
+++ b/producer-consumer/src/test/java/com/captaindebug/producerconsumer/poisonpill/TeletypeTest.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright 2013 Marin Solutions
+ */
+package com.captaindebug.producerconsumer.poisonpill;
+
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.captaindebug.producerconsumer.Message;
+import com.captaindebug.producerconsumer.PrintHead;
+
+/**
+ *
+ * TODO This will be part of another blog....
+ *
+ * @author Roger
+ *
+ */
+public class TeletypeTest {
+
+ private BlockingQueue queue;
+ private Teletype instance;
+ private PrintHead printhead;
+
+ @Before
+ public void setUp() throws Exception {
+
+ printhead = mock(PrintHead.class);
+ queue = new LinkedBlockingQueue();
+ }
+
+ @Test
+ public void testTeletype_terminate_with_poison_pill_with_one_match_played() throws InterruptedException {
+
+ final int numMatches = 1;
+ instance = new Teletype(printhead, queue, numMatches);
+ testTeletype_terminate_with_poison_pill(numMatches);
+ }
+
+ private void testTeletype_terminate_with_poison_pill(int numMatches) throws InterruptedException {
+
+ int numMessages = initializeQueueWithMessages(numMatches);
+ instance.start();
+
+ synchWithTestInstanceThread(numMessages);
+
+ // assert that we didn't time out.
+ assertFalse(instance.isRunning());
+ verify(printhead, atLeastOnce()).print(anyString());
+ }
+
+ private int initializeQueueWithMessages(int numMatches) {
+ List messages = getTestMessages(numMatches);
+ queue.addAll(messages);
+ int numMessages = messages.size();
+ return numMessages;
+ }
+
+ private List getTestMessages(int numMatches) {
+
+ List messages = new ArrayList();
+ addMessages(messages);
+ addPoisonPills(messages, numMatches);
+
+ return messages;
+ }
+
+ private void addMessages(List messages) {
+ Message message = new Message("name", 1L, "String messageText", "String matchTime");
+ messages.add(message);
+ message = new Message("name", 2L, "String messageText", "String matchTime");
+ messages.add(message);
+ }
+
+ private void addPoisonPills(List messages, int numMatches) {
+ for (int i = 0; i < numMatches; i++) {
+ Message message = new Message("name", 2L, "END OF FILE", "String matchTime");
+ messages.add(message);
+ }
+ }
+
+ private void synchWithTestInstanceThread(int numMessages) throws InterruptedException {
+
+ // Synchronize on the running flag..
+ // This will wait for 1/2 a second at most and then timeout
+ for (int i = 0; (i < 5) && (instance.isRunning()); i++) {
+
+ Thread.sleep(100);
+ }
+ }
+
+ @Test
+ public void testTeletype_terminate_with_poison_pill_with_two_matches_played() throws InterruptedException {
+
+ final int numMatches = 2;
+ instance = new Teletype(printhead, queue, numMatches);
+ testTeletype_terminate_with_poison_pill(numMatches);
+ }
+}
From 549b94cf7892cd69c6267e5a238d412c6f0b92da Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Thu, 21 Feb 2013 16:40:06 +0000
Subject: [PATCH 027/142] Completed Poison Pill code.
---
producer-consumer/pom.xml | 5 +++++
.../captaindebug/producerconsumer/poisonpill/Teletype.java | 4 +++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/producer-consumer/pom.xml b/producer-consumer/pom.xml
index 260808c..b2b3651 100644
--- a/producer-consumer/pom.xml
+++ b/producer-consumer/pom.xml
@@ -51,6 +51,11 @@
1.9.5test
+
+ com.google.guava
+ guava
+ 13.0.1
+
diff --git a/producer-consumer/src/main/java/com/captaindebug/producerconsumer/poisonpill/Teletype.java b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/poisonpill/Teletype.java
index 6147ad2..81d8968 100644
--- a/producer-consumer/src/main/java/com/captaindebug/producerconsumer/poisonpill/Teletype.java
+++ b/producer-consumer/src/main/java/com/captaindebug/producerconsumer/poisonpill/Teletype.java
@@ -4,6 +4,7 @@
import com.captaindebug.producerconsumer.Message;
import com.captaindebug.producerconsumer.PrintHead;
+import com.google.common.annotations.VisibleForTesting;
/**
* Models a teletype. Takes messaged from the queue and prints them. Blocks
@@ -73,7 +74,8 @@ private boolean allGamesAreOver(String messageText) {
return pillsRecieved == matchesPlayed ? true : false;
}
- public boolean isRunning() {
+ @VisibleForTesting
+ boolean isRunning() {
return run;
}
}
From 5325850f99a0c3746d496ac2eed19c069f671a7c Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sat, 23 Feb 2013 10:58:41 +0000
Subject: [PATCH 028/142] Completed code for upcoming blog "Five Ways of
Synchronising Multithreaded Integration Tests"
---
.../threading/bad_example/package-info.java | 10 ---
.../threading/future/ThreadWrapper.java | 36 +++++++++++
.../threading/good_example/package-info.java | 10 ---
.../threading/good_example2/package-info.java | 10 ---
.../threading/joinexample/ThreadWrapper.java | 59 +++++++++++++++++
.../threading/semaphore/ThreadWrapper.java | 64 +++++++++++++++++++
.../threading/future/ThreadWrapperTest.java | 27 ++++++++
.../joinexample/ThreadWrapperTest.java | 27 ++++++++
.../semaphore/ThreadWrapperTest.java | 30 +++++++++
9 files changed, 243 insertions(+), 30 deletions(-)
delete mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/package-info.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/future/ThreadWrapper.java
delete mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/package-info.java
delete mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/package-info.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/joinexample/ThreadWrapper.java
create mode 100644 unit-testing-threads/src/main/java/com/captaindebug/threading/semaphore/ThreadWrapper.java
create mode 100644 unit-testing-threads/src/test/java/com/captaindebug/threading/future/ThreadWrapperTest.java
create mode 100644 unit-testing-threads/src/test/java/com/captaindebug/threading/joinexample/ThreadWrapperTest.java
create mode 100644 unit-testing-threads/src/test/java/com/captaindebug/threading/semaphore/ThreadWrapperTest.java
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/package-info.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/package-info.java
deleted file mode 100644
index f6ad961..0000000
--- a/unit-testing-threads/src/main/java/com/captaindebug/threading/bad_example/package-info.java
+++ /dev/null
@@ -1,10 +0,0 @@
-/**
- *
- */
-/**
- * @author Roger
- *
- * Created 17:54:34 20 Jan 2013
- *
- */
-package com.captaindebug.threading.bad_example;
\ No newline at end of file
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/future/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/future/ThreadWrapper.java
new file mode 100644
index 0000000..792ee3c
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/future/ThreadWrapper.java
@@ -0,0 +1,36 @@
+/**
+ *
+ */
+package com.captaindebug.threading.future;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author Roger
+ *
+ * Created 18:35:58 20 Jan 2013
+ *
+ */
+public class ThreadWrapper implements Callable {
+
+ @Override
+ public Boolean call() throws Exception {
+ System.out.println("Start of the thread");
+ Boolean added = addDataToDB();
+ System.out.println("End of the thread method");
+ return added;
+ }
+
+ /**
+ * Add to the DB and return true if added okay
+ */
+ private Boolean addDataToDB() {
+
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return Boolean.valueOf(true);
+ }
+}
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/package-info.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/package-info.java
deleted file mode 100644
index 66e1b21..0000000
--- a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example/package-info.java
+++ /dev/null
@@ -1,10 +0,0 @@
-/**
- *
- */
-/**
- * @author Roger
- *
- * Created 17:54:49 20 Jan 2013
- *
- */
-package com.captaindebug.threading.good_example;
\ No newline at end of file
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/package-info.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/package-info.java
deleted file mode 100644
index 5953362..0000000
--- a/unit-testing-threads/src/main/java/com/captaindebug/threading/good_example2/package-info.java
+++ /dev/null
@@ -1,10 +0,0 @@
-/**
- *
- */
-/**
- * @author Roger
- *
- * Created 20:45:26 26 Jan 2013
- *
- */
-package com.captaindebug.threading.good_example2;
\ No newline at end of file
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/joinexample/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/joinexample/ThreadWrapper.java
new file mode 100644
index 0000000..a3711de
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/joinexample/ThreadWrapper.java
@@ -0,0 +1,59 @@
+/**
+ *
+ */
+package com.captaindebug.threading.joinexample;
+
+/**
+ * @author Roger
+ *
+ * Created 18:35:58 20 Jan 2013
+ *
+ */
+public class ThreadWrapper {
+
+ private Thread thread;
+
+ /**
+ * Start the thread running so that it does some work.
+ */
+ public void doWork() {
+
+ thread = new Thread() {
+
+ /**
+ * Run method adding data to a fictitious database
+ */
+ @Override
+ public void run() {
+
+ System.out.println("Start of the thread");
+ addDataToDB();
+ System.out.println("End of the thread method");
+ }
+
+ private void addDataToDB() {
+
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+
+ thread.start();
+ System.out.println("Off and running...");
+ }
+
+ /**
+ * Synchronization method.
+ */
+ public void join() {
+
+ try {
+ thread.join();
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+ }
+}
diff --git a/unit-testing-threads/src/main/java/com/captaindebug/threading/semaphore/ThreadWrapper.java b/unit-testing-threads/src/main/java/com/captaindebug/threading/semaphore/ThreadWrapper.java
new file mode 100644
index 0000000..dce8295
--- /dev/null
+++ b/unit-testing-threads/src/main/java/com/captaindebug/threading/semaphore/ThreadWrapper.java
@@ -0,0 +1,64 @@
+/**
+ *
+ */
+package com.captaindebug.threading.semaphore;
+
+import java.util.concurrent.Semaphore;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * @author Roger
+ *
+ * Created 18:35:58 20 Jan 2013
+ *
+ */
+public class ThreadWrapper {
+
+ /**
+ * Start the thread running so that it does some work.
+ */
+ public void doWork() {
+ doWork(null);
+ }
+
+ @VisibleForTesting
+ void doWork(final Semaphore semaphore) {
+
+ Thread thread = new Thread() {
+
+ /**
+ * Run method adding data to a fictitious database
+ */
+ @Override
+ public void run() {
+
+ System.out.println("Start of the thread");
+ addDataToDB();
+ System.out.println("End of the thread method");
+ semaphore.release();
+ }
+
+ private void addDataToDB() {
+
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+
+ aquire(semaphore);
+ thread.start();
+ System.out.println("Off and running...");
+ }
+
+ private void aquire(Semaphore semaphore) {
+ try {
+ semaphore.acquire();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/unit-testing-threads/src/test/java/com/captaindebug/threading/future/ThreadWrapperTest.java b/unit-testing-threads/src/test/java/com/captaindebug/threading/future/ThreadWrapperTest.java
new file mode 100644
index 0000000..a670198
--- /dev/null
+++ b/unit-testing-threads/src/test/java/com/captaindebug/threading/future/ThreadWrapperTest.java
@@ -0,0 +1,27 @@
+package com.captaindebug.threading.future;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.junit.Test;
+
+public class ThreadWrapperTest {
+
+ @Test
+ public void testCall() throws ExecutionException, InterruptedException {
+
+ ThreadWrapper instance = new ThreadWrapper();
+
+ ExecutorService executorService = Executors.newFixedThreadPool(1);
+
+ Future future = executorService.submit(instance);
+
+ Boolean result = future.get();
+
+ assertTrue(result);
+ }
+}
diff --git a/unit-testing-threads/src/test/java/com/captaindebug/threading/joinexample/ThreadWrapperTest.java b/unit-testing-threads/src/test/java/com/captaindebug/threading/joinexample/ThreadWrapperTest.java
new file mode 100644
index 0000000..5af27c4
--- /dev/null
+++ b/unit-testing-threads/src/test/java/com/captaindebug/threading/joinexample/ThreadWrapperTest.java
@@ -0,0 +1,27 @@
+package com.captaindebug.threading.joinexample;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class ThreadWrapperTest {
+
+ @Test
+ public void testDoWork() throws InterruptedException {
+
+ ThreadWrapper instance = new ThreadWrapper();
+
+ instance.doWork();
+ instance.join();
+
+ boolean result = getResultFromDatabase();
+ assertTrue(result);
+ }
+
+ /**
+ * Dummy database method - just return true
+ */
+ private boolean getResultFromDatabase() {
+ return true;
+ }
+}
diff --git a/unit-testing-threads/src/test/java/com/captaindebug/threading/semaphore/ThreadWrapperTest.java b/unit-testing-threads/src/test/java/com/captaindebug/threading/semaphore/ThreadWrapperTest.java
new file mode 100644
index 0000000..3a1bc65
--- /dev/null
+++ b/unit-testing-threads/src/test/java/com/captaindebug/threading/semaphore/ThreadWrapperTest.java
@@ -0,0 +1,30 @@
+package com.captaindebug.threading.semaphore;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.Semaphore;
+
+import org.junit.Test;
+
+public class ThreadWrapperTest {
+
+ @Test
+ public void testDoWork() throws InterruptedException {
+
+ ThreadWrapper instance = new ThreadWrapper();
+
+ Semaphore semaphore = new Semaphore(1);
+ instance.doWork(semaphore);
+ semaphore.acquire();
+
+ boolean result = getResultFromDatabase();
+ assertTrue(result);
+ }
+
+ /**
+ * Dummy database method - just return true
+ */
+ private boolean getResultFromDatabase() {
+ return true;
+ }
+}
From 9ccaa7642f88e699c6fbac58bbc88d68f206275c Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sun, 24 Feb 2013 10:49:17 +0000
Subject: [PATCH 029/142] Updated to Spring 3.2.1-RELEASE
---
address/pom.xml | 9 ++++++---
.../WEB-INF/spring/appServlet/servlet-context.xml | 9 +++++----
.../spring/appServlet/spring-datasource.xml | 6 +++---
.../main/webapp/WEB-INF/spring/root-context.xml | 2 +-
address/src/test/resources/servlet-context.xml | 6 +++---
exceptions/pom.xml | 11 ++++-------
.../WEB-INF/spring/appServlet/servlet-context.xml | 6 +++---
.../main/webapp/WEB-INF/spring/root-context.xml | 2 +-
facebook/pom.xml | 14 ++++++--------
.../WEB-INF/spring/appServlet/servlet-context.xml | 6 +++---
facebook/src/main/webapp/WEB-INF/spring/data.xml | 8 ++++----
.../main/webapp/WEB-INF/spring/root-context.xml | 2 +-
producer-consumer/pom.xml | 2 +-
.../src/main/resources/matches-poisonpill.xml | 4 ++--
producer-consumer/src/main/resources/matches.xml | 4 ++--
sim-map-exc-res/pom.xml | 7 ++++++-
.../WEB-INF/spring/appServlet/servlet-context.xml | 6 +++---
.../main/webapp/WEB-INF/spring/root-context.xml | 2 +-
social/pom.xml | 14 ++++++--------
.../main/webapp/WEB-INF/spring/root-context.xml | 2 +-
spring-security/tomcat-ssl/pom.xml | 8 ++++++--
.../spring/appServlet/application-security.xml | 2 +-
.../WEB-INF/spring/appServlet/servlet-context.xml | 6 +++---
.../main/webapp/WEB-INF/spring/root-context.xml | 2 +-
.../WEB-INF/spring/appServlet/servlet-context.xml | 6 +++---
.../main/webapp/WEB-INF/spring/root-context.xml | 2 +-
26 files changed, 77 insertions(+), 71 deletions(-)
diff --git a/address/pom.xml b/address/pom.xml
index 2b62a5a..b1e7ccb 100644
--- a/address/pom.xml
+++ b/address/pom.xml
@@ -9,7 +9,7 @@
1.0.0-BUILD-SNAPSHOT1.6
- 3.0.5.RELEASE
+ 3.2.1.RELEASE1.5.103.1
@@ -32,14 +32,17 @@
spring-webmvc${org.springframework-version}
-
+
+ org.springframework
+ spring-web
+ ${org.springframework-version}
+ org.springframeworkspring-jdbc${org.springframework-version}
-
org.slf4j
diff --git a/address/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/address/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
index 150a62c..3a63d26 100644
--- a/address/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ b/address/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -1,10 +1,11 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
diff --git a/address/src/main/webapp/WEB-INF/spring/appServlet/spring-datasource.xml b/address/src/main/webapp/WEB-INF/spring/appServlet/spring-datasource.xml
index 7b7121f..9b473be 100644
--- a/address/src/main/webapp/WEB-INF/spring/appServlet/spring-datasource.xml
+++ b/address/src/main/webapp/WEB-INF/spring/appServlet/spring-datasource.xml
@@ -3,11 +3,11 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
- http://www.springframework.org/schema/beans/spring-context-3.0.xsd
+ http://www.springframework.org/schema/beans/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
- http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
+ http://www.springframework.org/schema/jee/spring-jee-3.2.xsd">
diff --git a/address/src/main/webapp/WEB-INF/spring/root-context.xml b/address/src/main/webapp/WEB-INF/spring/root-context.xml
index c38cdff..e5f58b4 100644
--- a/address/src/main/webapp/WEB-INF/spring/root-context.xml
+++ b/address/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -1,7 +1,7 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
diff --git a/address/src/test/resources/servlet-context.xml b/address/src/test/resources/servlet-context.xml
index adcc373..0125f94 100644
--- a/address/src/test/resources/servlet-context.xml
+++ b/address/src/test/resources/servlet-context.xml
@@ -2,9 +2,9 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
diff --git a/exceptions/pom.xml b/exceptions/pom.xml
index 25769ff..36dcb41 100644
--- a/exceptions/pom.xml
+++ b/exceptions/pom.xml
@@ -9,8 +9,7 @@
1.0.0-BUILD-SNAPSHOT1.6
- 3.0.5.RELEASE
- 1.0.2.RELEASE
+ 3.2.1.RELEASE1.6.91.5.10
@@ -33,12 +32,10 @@
spring-webmvc${org.springframework-version}
-
- org.springframework.roo
- org.springframework.roo.annotations
- ${org.springframework.roo-version}
- provided
+ org.springframework
+ spring-web
+ ${org.springframework-version}
diff --git a/exceptions/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/exceptions/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
index efe307b..167b3a7 100644
--- a/exceptions/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ b/exceptions/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -3,9 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
diff --git a/exceptions/src/main/webapp/WEB-INF/spring/root-context.xml b/exceptions/src/main/webapp/WEB-INF/spring/root-context.xml
index c38cdff..e5f58b4 100644
--- a/exceptions/src/main/webapp/WEB-INF/spring/root-context.xml
+++ b/exceptions/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -1,7 +1,7 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
diff --git a/facebook/pom.xml b/facebook/pom.xml
index bc283bf..74b53c3 100644
--- a/facebook/pom.xml
+++ b/facebook/pom.xml
@@ -9,7 +9,7 @@
1.0.0-BUILD-SNAPSHOT1.6
- 3.0.6.RELEASE
+ 3.2.1.RELEASE1.6.91.0.2.RELEASE1.0.1.RELEASE
@@ -36,6 +36,11 @@
spring-webmvc${org.springframework-version}
+
+ org.springframework
+ spring-web
+ ${org.springframework-version}
+
@@ -159,13 +164,6 @@
1.3.159
-
-
- cglib
- cglib-nodep
- 2.2
-
-
org.unitilsunitils-core
diff --git a/facebook/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/facebook/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
index b6dcf68..0d46e05 100644
--- a/facebook/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ b/facebook/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -3,9 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
diff --git a/facebook/src/main/webapp/WEB-INF/spring/data.xml b/facebook/src/main/webapp/WEB-INF/spring/data.xml
index c412263..32ef440 100644
--- a/facebook/src/main/webapp/WEB-INF/spring/data.xml
+++ b/facebook/src/main/webapp/WEB-INF/spring/data.xml
@@ -4,10 +4,10 @@
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
diff --git a/facebook/src/main/webapp/WEB-INF/spring/root-context.xml b/facebook/src/main/webapp/WEB-INF/spring/root-context.xml
index 0fe0707..8060b70 100644
--- a/facebook/src/main/webapp/WEB-INF/spring/root-context.xml
+++ b/facebook/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -1,7 +1,7 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
diff --git a/producer-consumer/pom.xml b/producer-consumer/pom.xml
index b2b3651..5f5206c 100644
--- a/producer-consumer/pom.xml
+++ b/producer-consumer/pom.xml
@@ -9,7 +9,7 @@
Example Producer Consumer Pattern1.6.1
- 3.0.5.RELEASE
+ 3.2.1.RELEASE
diff --git a/producer-consumer/src/main/resources/matches-poisonpill.xml b/producer-consumer/src/main/resources/matches-poisonpill.xml
index 9e7ca72..1fd8c98 100644
--- a/producer-consumer/src/main/resources/matches-poisonpill.xml
+++ b/producer-consumer/src/main/resources/matches-poisonpill.xml
@@ -2,8 +2,8 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
diff --git a/producer-consumer/src/main/resources/matches.xml b/producer-consumer/src/main/resources/matches.xml
index a2c7bf3..7a36a7f 100644
--- a/producer-consumer/src/main/resources/matches.xml
+++ b/producer-consumer/src/main/resources/matches.xml
@@ -2,8 +2,8 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
diff --git a/sim-map-exc-res/pom.xml b/sim-map-exc-res/pom.xml
index 73f7421..b94d1e4 100644
--- a/sim-map-exc-res/pom.xml
+++ b/sim-map-exc-res/pom.xml
@@ -9,7 +9,7 @@
1.0.0-BUILD-SNAPSHOT1.6
- 3.0.6.RELEASE
+ 3.2.1.RELEASE1.6.91.5.10
@@ -32,6 +32,11 @@
spring-webmvc${org.springframework-version}
+
+ org.springframework
+ spring-web
+ ${org.springframework-version}
+
diff --git a/sim-map-exc-res/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/sim-map-exc-res/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
index e687397..fdf7182 100644
--- a/sim-map-exc-res/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ b/sim-map-exc-res/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -3,9 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
diff --git a/sim-map-exc-res/src/main/webapp/WEB-INF/spring/root-context.xml b/sim-map-exc-res/src/main/webapp/WEB-INF/spring/root-context.xml
index c38cdff..e5f58b4 100644
--- a/sim-map-exc-res/src/main/webapp/WEB-INF/spring/root-context.xml
+++ b/sim-map-exc-res/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -1,7 +1,7 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
diff --git a/social/pom.xml b/social/pom.xml
index 2e2aba5..834070e 100644
--- a/social/pom.xml
+++ b/social/pom.xml
@@ -9,7 +9,7 @@
1.0.0-BUILD-SNAPSHOT1.6
- 3.0.6.RELEASE
+ 3.2.1.RELEASE1.6.91.5.101.0.2.RELEASE
@@ -35,6 +35,11 @@
spring-webmvc${org.springframework-version}
+
+ org.springframework
+ spring-web
+ ${org.springframework-version}
+
@@ -127,13 +132,6 @@
${org.springframework.social-twitter-version}
-
-
- cglib
- cglib-nodep
- 2.2
-
-
com.captaindebugstate-machine
diff --git a/social/src/main/webapp/WEB-INF/spring/root-context.xml b/social/src/main/webapp/WEB-INF/spring/root-context.xml
index c38cdff..e5f58b4 100644
--- a/social/src/main/webapp/WEB-INF/spring/root-context.xml
+++ b/social/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -1,7 +1,7 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
diff --git a/spring-security/tomcat-ssl/pom.xml b/spring-security/tomcat-ssl/pom.xml
index 539c950..cde1163 100644
--- a/spring-security/tomcat-ssl/pom.xml
+++ b/spring-security/tomcat-ssl/pom.xml
@@ -9,7 +9,7 @@
1.0.0-BUILD-SNAPSHOT1.6
- 3.1.0.RELEASE
+ 3.2.1.RELEASE3.1.3.RELEASE1.6.91.5.10
@@ -33,7 +33,11 @@
spring-webmvc${org.springframework-version}
-
+
+ org.springframework
+ spring-web
+ ${org.springframework-version}
+ org.aspectj
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml
index 6a34d56..251080c 100644
--- a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/application-security.xml
@@ -3,7 +3,7 @@
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
index 4ece2e7..ba4852d 100644
--- a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -3,9 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
diff --git a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/root-context.xml b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/root-context.xml
index c38cdff..e5f58b4 100644
--- a/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/root-context.xml
+++ b/spring-security/tomcat-ssl/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -1,7 +1,7 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
diff --git a/telldontask/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/telldontask/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
index 34cd976..d03b2ba 100644
--- a/telldontask/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ b/telldontask/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -3,9 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
diff --git a/telldontask/src/main/webapp/WEB-INF/spring/root-context.xml b/telldontask/src/main/webapp/WEB-INF/spring/root-context.xml
index c38cdff..e5f58b4 100644
--- a/telldontask/src/main/webapp/WEB-INF/spring/root-context.xml
+++ b/telldontask/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -1,7 +1,7 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
From 5230ad6cf2128ffae49efdd27f8386a0a40b3f53 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Thu, 7 Mar 2013 23:08:39 +0000
Subject: [PATCH 030/142] Defensive programming sample code
---
build-all/pom.xml | 1 +
defensive/.gitignore | 4 +
defensive/pom.xml | 77 +++++++++++++++++++
.../defensive/badsample/BodyMassIndex.java | 5 ++
.../defensive/goodsample/BodyMassIndex.java | 5 ++
defensive/src/main/resources/context.xml | 32 ++++++++
.../badsample/BodyMassIndexTest.java | 16 ++++
.../goodsample/BodyMassIndexTest.java | 16 ++++
8 files changed, 156 insertions(+)
create mode 100644 defensive/.gitignore
create mode 100644 defensive/pom.xml
create mode 100644 defensive/src/main/java/com/captaindebug/defensive/badsample/BodyMassIndex.java
create mode 100644 defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java
create mode 100644 defensive/src/main/resources/context.xml
create mode 100644 defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java
create mode 100644 defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java
diff --git a/build-all/pom.xml b/build-all/pom.xml
index d8e0131..732a690 100644
--- a/build-all/pom.xml
+++ b/build-all/pom.xml
@@ -24,5 +24,6 @@
../spring-security/tomcat-ssl../unit-testing-threads../producer-consumer
+ ../defensive
\ No newline at end of file
diff --git a/defensive/.gitignore b/defensive/.gitignore
new file mode 100644
index 0000000..29052a9
--- /dev/null
+++ b/defensive/.gitignore
@@ -0,0 +1,4 @@
+/.project
+/.settings
+/.classpath
+/target
diff --git a/defensive/pom.xml b/defensive/pom.xml
new file mode 100644
index 0000000..892f936
--- /dev/null
+++ b/defensive/pom.xml
@@ -0,0 +1,77 @@
+
+
+ 4.0.0
+ com.captaindebug
+ defensive-programming
+ jar
+ 1.0-SNAPSHOT
+ Defensive Programming
+
+ 1.6.1
+ 3.2.1.RELEASE
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4jVersion}
+
+
+
+ org.slf4j
+ slf4j-log4j12
+ ${slf4jVersion}
+ runtime
+
+
+ log4j
+ log4j
+ 1.2.16
+ runtime
+
+
+ junit
+ junit
+ 4.8.2
+ test
+
+
+ org.springframework
+ spring-context
+ ${org.springframework-version}
+
+
+ org.mockito
+ mockito-all
+ 1.9.5
+ test
+
+
+ com.google.guava
+ guava
+ 13.0.1
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.7
+ 1.7
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.6
+
+
+
+
diff --git a/defensive/src/main/java/com/captaindebug/defensive/badsample/BodyMassIndex.java b/defensive/src/main/java/com/captaindebug/defensive/badsample/BodyMassIndex.java
new file mode 100644
index 0000000..1987bc2
--- /dev/null
+++ b/defensive/src/main/java/com/captaindebug/defensive/badsample/BodyMassIndex.java
@@ -0,0 +1,5 @@
+package com.captaindebug.defensive.badsample;
+
+public class BodyMassIndex {
+
+}
diff --git a/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java b/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java
new file mode 100644
index 0000000..2b446a6
--- /dev/null
+++ b/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java
@@ -0,0 +1,5 @@
+package com.captaindebug.defensive.goodsample;
+
+public class BodyMassIndex {
+
+}
diff --git a/defensive/src/main/resources/context.xml b/defensive/src/main/resources/context.xml
new file mode 100644
index 0000000..1cba79c
--- /dev/null
+++ b/defensive/src/main/resources/context.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java b/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java
new file mode 100644
index 0000000..4f27f6f
--- /dev/null
+++ b/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java
@@ -0,0 +1,16 @@
+package com.captaindebug.defensive.badsample;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class BodyMassIndexTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void test() {
+ }
+
+}
diff --git a/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java b/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java
new file mode 100644
index 0000000..7f5e775
--- /dev/null
+++ b/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java
@@ -0,0 +1,16 @@
+package com.captaindebug.defensive.goodsample;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class BodyMassIndexTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void test() {
+ }
+
+}
From a1d173119826ad59333dc4db6e524aea26f1918b Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sat, 9 Mar 2013 09:48:25 +0000
Subject: [PATCH 031/142] Completed defensive programming sample
---
defensive/pom.xml | 5 +++
.../defensive/badsample/BodyMassIndex.java | 24 +++++++++++
.../defensive/goodsample/BodyMassIndex.java | 26 ++++++++++++
.../badsample/BodyMassIndexTest.java | 40 ++++++++++++++++++-
.../goodsample/BodyMassIndexTest.java | 36 ++++++++++++++++-
5 files changed, 129 insertions(+), 2 deletions(-)
diff --git a/defensive/pom.xml b/defensive/pom.xml
index 892f936..98ecfd5 100644
--- a/defensive/pom.xml
+++ b/defensive/pom.xml
@@ -55,6 +55,11 @@
guava13.0.1
+
+ org.apache.commons
+ commons-lang3
+ 3.1
+
diff --git a/defensive/src/main/java/com/captaindebug/defensive/badsample/BodyMassIndex.java b/defensive/src/main/java/com/captaindebug/defensive/badsample/BodyMassIndex.java
index 1987bc2..24ecc19 100644
--- a/defensive/src/main/java/com/captaindebug/defensive/badsample/BodyMassIndex.java
+++ b/defensive/src/main/java/com/captaindebug/defensive/badsample/BodyMassIndex.java
@@ -1,5 +1,29 @@
package com.captaindebug.defensive.badsample;
+import java.math.BigDecimal;
+import java.math.MathContext;
+
public class BodyMassIndex {
+ /**
+ * Calculate the BMI using Weight(kg) / height(m)2
+ *
+ * @return Returns the BMI to four significant figures eg nn.nn
+ */
+ public Double calculate(Double weight, Double height) {
+
+ Double result = null;
+
+ if ((weight != null) && (height != null) && (weight > 0.0) && (height > 0.0)) {
+
+ Double tmp = weight / (height * height);
+
+ BigDecimal bd = new BigDecimal(tmp);
+ MathContext mathContext = new MathContext(4);
+ bd = bd.round(mathContext);
+ result = bd.doubleValue();
+ }
+
+ return result;
+ }
}
diff --git a/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java b/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java
index 2b446a6..5fa3784 100644
--- a/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java
+++ b/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java
@@ -1,5 +1,31 @@
package com.captaindebug.defensive.goodsample;
+import java.math.BigDecimal;
+import java.math.MathContext;
+
+import org.apache.commons.lang3.Validate;
+
public class BodyMassIndex {
+ /**
+ * Calculate the BMI using Weight(kg) / height(m)2
+ *
+ * @return Returns the BMI to four significant figures eg nn.nn
+ */
+ public Double calculate(Double weight, Double height) {
+
+ Validate.notNull(weight, "Your weight cannot be null");
+ Validate.notNull(height, "Your height cannot be null");
+
+ Validate.validState(weight.doubleValue() > 0);
+ Validate.validState(height.doubleValue() > 0);
+
+ Double tmp = weight / (height * height);
+
+ BigDecimal result = new BigDecimal(tmp);
+ MathContext mathContext = new MathContext(4);
+ result = result.round(mathContext);
+
+ return result.doubleValue();
+ }
}
diff --git a/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java b/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java
index 4f27f6f..2567c9d 100644
--- a/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java
+++ b/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java
@@ -1,16 +1,54 @@
package com.captaindebug.defensive.badsample;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
import org.junit.Before;
import org.junit.Test;
public class BodyMassIndexTest {
+ private BodyMassIndex instance;
+
@Before
public void setUp() throws Exception {
+ instance = new BodyMassIndex();
+ }
+
+ @Test
+ public void test_valid_inputs() {
+
+ final Double expectedResult = 26.23;
+
+ Double result = instance.calculate(85.0, 1.8);
+ assertEquals(expectedResult, result);
}
@Test
- public void test() {
+ public void test_null_weight_input() {
+
+ Double result = instance.calculate(null, 1.8);
+ assertNull(result);
}
+ @Test
+ public void test_null_height_input() {
+
+ Double result = instance.calculate(75.0, null);
+ assertNull(result);
+ }
+
+ @Test
+ public void test_zero_height_input() {
+
+ Double result = instance.calculate(75.0, 0.0);
+ assertNull(result);
+ }
+
+ @Test
+ public void test_zero_weight_input() {
+
+ Double result = instance.calculate(0.0, 1.8);
+ assertNull(result);
+ }
}
diff --git a/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java b/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java
index 7f5e775..4fd2928 100644
--- a/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java
+++ b/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java
@@ -1,16 +1,50 @@
package com.captaindebug.defensive.goodsample;
+import static org.junit.Assert.assertEquals;
+
import org.junit.Before;
import org.junit.Test;
public class BodyMassIndexTest {
+ private BodyMassIndex instance;
+
@Before
public void setUp() throws Exception {
+ instance = new BodyMassIndex();
}
@Test
- public void test() {
+ public void test_valid_inputs() {
+
+ final Double expectedResult = 26.23;
+
+ Double result = instance.calculate(85.0, 1.8);
+ assertEquals(expectedResult, result);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void test_null_weight_input() {
+
+ instance.calculate(null, 1.8);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void test_null_height_input() {
+
+ instance.calculate(75.0, null);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void test_zero_height_input() {
+
+ instance.calculate(75.0, 0.0);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void test_zero_weight_input() {
+
+ instance.calculate(0.0, 1.8);
}
}
From f780ee90f78260a278f9348ef5b6ab51e2e3bcc2 Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sun, 10 Mar 2013 13:06:01 +0000
Subject: [PATCH 032/142] Completed defensive coding sample.
---
.../defensive/goodsample/BodyMassIndex.java | 4 ++--
.../defensive/badsample/BodyMassIndexTest.java | 12 ++++++++++++
.../defensive/goodsample/BodyMassIndexTest.java | 1 -
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java b/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java
index 5fa3784..a0e3d14 100644
--- a/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java
+++ b/defensive/src/main/java/com/captaindebug/defensive/goodsample/BodyMassIndex.java
@@ -17,8 +17,8 @@ public Double calculate(Double weight, Double height) {
Validate.notNull(weight, "Your weight cannot be null");
Validate.notNull(height, "Your height cannot be null");
- Validate.validState(weight.doubleValue() > 0);
- Validate.validState(height.doubleValue() > 0);
+ Validate.validState(weight.doubleValue() > 0, "Your weight cannot be zero");
+ Validate.validState(height.doubleValue() > 0, "Your height cannot be zero");
Double tmp = weight / (height * height);
diff --git a/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java b/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java
index 2567c9d..8fcb78a 100644
--- a/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java
+++ b/defensive/src/test/java/com/captaindebug/defensive/badsample/BodyMassIndexTest.java
@@ -51,4 +51,16 @@ public void test_zero_weight_input() {
Double result = instance.calculate(0.0, 1.8);
assertNull(result);
}
+
+ @Test
+ public void test_zero_weight_input_forces_additional_checks() {
+
+ Double result = instance.calculate(0.0, 1.8);
+ if (result == null) {
+ System.out.println("Incorrect input to BMI calculation");
+ // process the error
+ } else {
+ System.out.println("Your BMI is: " + result.doubleValue());
+ }
+ }
}
diff --git a/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java b/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java
index 4fd2928..7bf4726 100644
--- a/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java
+++ b/defensive/src/test/java/com/captaindebug/defensive/goodsample/BodyMassIndexTest.java
@@ -46,5 +46,4 @@ public void test_zero_weight_input() {
instance.calculate(0.0, 1.8);
}
-
}
From ebe830a40a022810eb757215ee0e039430e76a0f Mon Sep 17 00:00:00 2001
From: Roger Hughes
Date: Sat, 16 Mar 2013 22:45:38 +0000
Subject: [PATCH 033/142] Added Spring 3.2 ControllerAdvice Sample
---
spring-3.2/.gitignore | 4 +
spring-3.2/pom.xml | 168 ++++++++++++++++++
.../spring_3_2/HomeController.java | 39 ++++
.../MyControllerAdviceDemo.java | 43 +++++
.../UserAddressController.java | 37 ++++
.../UserCreditCardController.java | 37 ++++
.../controleradvice/beans/User.java | 27 +++
.../controleradvice/dao/UserDao.java | 21 +++
spring-3.2/src/main/resources/log4j.xml | 41 +++++
.../spring/appServlet/servlet-context.xml | 28 +++
.../webapp/WEB-INF/spring/root-context.xml | 8 +
.../src/main/webapp/WEB-INF/views/error.jsp | 17 ++
.../src/main/webapp/WEB-INF/views/home.jsp | 22 +++
spring-3.2/src/main/webapp/WEB-INF/web.xml | 33 ++++
spring-3.2/src/test/resources/log4j.xml | 41 +++++
15 files changed, 566 insertions(+)
create mode 100644 spring-3.2/.gitignore
create mode 100644 spring-3.2/pom.xml
create mode 100644 spring-3.2/src/main/java/com/captaindebug/spring_3_2/HomeController.java
create mode 100644 spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/MyControllerAdviceDemo.java
create mode 100644 spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/UserAddressController.java
create mode 100644 spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/UserCreditCardController.java
create mode 100644 spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/beans/User.java
create mode 100644 spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/dao/UserDao.java
create mode 100644 spring-3.2/src/main/resources/log4j.xml
create mode 100644 spring-3.2/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
create mode 100644 spring-3.2/src/main/webapp/WEB-INF/spring/root-context.xml
create mode 100644 spring-3.2/src/main/webapp/WEB-INF/views/error.jsp
create mode 100644 spring-3.2/src/main/webapp/WEB-INF/views/home.jsp
create mode 100644 spring-3.2/src/main/webapp/WEB-INF/web.xml
create mode 100644 spring-3.2/src/test/resources/log4j.xml
diff --git a/spring-3.2/.gitignore b/spring-3.2/.gitignore
new file mode 100644
index 0000000..c708c36
--- /dev/null
+++ b/spring-3.2/.gitignore
@@ -0,0 +1,4 @@
+/target
+/.settings
+/.classpath
+/.project
diff --git a/spring-3.2/pom.xml b/spring-3.2/pom.xml
new file mode 100644
index 0000000..db24186
--- /dev/null
+++ b/spring-3.2/pom.xml
@@ -0,0 +1,168 @@
+
+
+ 4.0.0
+ com.captaindebug
+ spring_3_2
+ spring-3.2
+ war
+ 1.0.0-BUILD-SNAPSHOT
+
+ 1.7
+ 3.2.2.RELEASE
+ 1.6.10
+ 1.6.6
+
+
+
+
+ org.springframework
+ spring-context
+ ${org.springframework-version}
+
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ org.springframework
+ spring-webmvc
+ ${org.springframework-version}
+
+
+
+
+ org.aspectj
+ aspectjrt
+ ${org.aspectj-version}
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${org.slf4j-version}
+
+
+ org.slf4j
+ jcl-over-slf4j
+ ${org.slf4j-version}
+ runtime
+
+
+ org.slf4j
+ slf4j-log4j12
+ ${org.slf4j-version}
+ runtime
+
+
+ log4j
+ log4j
+ 1.2.15
+
+
+ javax.mail
+ mail
+
+
+ javax.jms
+ jms
+
+
+ com.sun.jdmk
+ jmxtools
+
+
+ com.sun.jmx
+ jmxri
+
+
+ runtime
+
+
+
+
+ javax.inject
+ javax.inject
+ 1
+
+
+
+
+ javax.servlet
+ servlet-api
+ 2.5
+ provided
+
+
+ javax.servlet.jsp
+ jsp-api
+ 2.1
+ provided
+
+
+ javax.servlet
+ jstl
+ 1.2
+
+
+
+
+ junit
+ junit
+ 4.7
+ test
+
+
+
+
+
+ maven-eclipse-plugin
+ 2.9
+
+
+ org.springframework.ide.eclipse.core.springnature
+
+
+ org.springframework.ide.eclipse.core.springbuilder
+
+ true
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.5.1
+
+ 1.7
+ 1.7
+ -Xlint:all
+ true
+ true
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.2.1
+
+ org.test.int1.Main
+
+
+
+ org.codehaus.mojo
+ tomcat-maven-plugin
+ 1.1
+
+ myserver
+ http://localhost:8080/manager/text
+
+
+
+
+
+
diff --git a/spring-3.2/src/main/java/com/captaindebug/spring_3_2/HomeController.java b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/HomeController.java
new file mode 100644
index 0000000..5f793ff
--- /dev/null
+++ b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/HomeController.java
@@ -0,0 +1,39 @@
+package com.captaindebug.spring_3_2;
+
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * Handles requests for the application home page.
+ */
+@Controller
+public class HomeController {
+
+ private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
+
+ /**
+ * Simply selects the home view to render by returning its name.
+ */
+ @RequestMapping(value = "/", method = RequestMethod.GET)
+ public String home(Locale locale, Model model) {
+ logger.info("Welcome home! The client locale is {}.", locale);
+
+ Date date = new Date();
+ DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
+
+ String formattedDate = dateFormat.format(date);
+
+ model.addAttribute("serverTime", formattedDate );
+
+ return "home";
+ }
+
+}
diff --git a/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/MyControllerAdviceDemo.java b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/MyControllerAdviceDemo.java
new file mode 100644
index 0000000..a6b1e68
--- /dev/null
+++ b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/MyControllerAdviceDemo.java
@@ -0,0 +1,43 @@
+package com.captaindebug.spring_3_2.controleradvice;
+
+import java.io.IOException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.captaindebug.spring_3_2.controleradvice.dao.UserDao;
+
+@ControllerAdvice
+public class MyControllerAdviceDemo {
+
+ private static final Logger logger = LoggerFactory.getLogger(MyControllerAdviceDemo.class);
+
+ @Autowired
+ private UserDao userDao;
+
+ /**
+ * Catch IOException and redirect to a 'personal' page.
+ */
+ @ExceptionHandler(IOException.class)
+ public ModelAndView handleIOException(IOException ex) {
+
+ logger.info("handleIOException - Catching: " + ex.getClass().getSimpleName());
+ return errorModelAndView(ex);
+ }
+
+ /**
+ * Get the users details for the 'personal' page
+ */
+ private ModelAndView errorModelAndView(Exception ex) {
+ ModelAndView modelAndView = new ModelAndView();
+ modelAndView.setViewName("error");
+ modelAndView.addObject("name", ex.getClass().getSimpleName());
+ modelAndView.addObject("user", userDao.readUserName());
+
+ return modelAndView;
+ }
+}
diff --git a/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/UserAddressController.java b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/UserAddressController.java
new file mode 100644
index 0000000..724029f
--- /dev/null
+++ b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/UserAddressController.java
@@ -0,0 +1,37 @@
+package com.captaindebug.spring_3_2.controleradvice;
+
+import java.io.IOException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * Handles requests for user address
+ */
+@Controller
+public class UserAddressController {
+
+ private static final Logger logger = LoggerFactory.getLogger(UserAddressController.class);
+
+ /**
+ * Whoops, throw an IOException
+ */
+ @RequestMapping(value = "useraddress", method = RequestMethod.GET)
+ public String getUserAddress(Model model) throws IOException {
+
+ logger.info("This will throw an IOException");
+
+ boolean throwException = true;
+
+ if (throwException) {
+ throw new IOException("This is my IOException");
+ }
+
+ return "home";
+ }
+
+}
diff --git a/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/UserCreditCardController.java b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/UserCreditCardController.java
new file mode 100644
index 0000000..80f4051
--- /dev/null
+++ b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/UserCreditCardController.java
@@ -0,0 +1,37 @@
+package com.captaindebug.spring_3_2.controleradvice;
+
+import java.io.IOException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * Handles requests for user name address
+ */
+@Controller
+public class UserCreditCardController {
+
+ private static final Logger logger = LoggerFactory.getLogger(UserCreditCardController.class);
+
+ /**
+ * Whoops, throw an IOException
+ */
+ @RequestMapping(value = "userdetails", method = RequestMethod.GET)
+ public String getCardDetails(Model model) throws IOException {
+
+ logger.info("This will throw an IOException");
+
+ boolean throwException = true;
+
+ if (throwException) {
+ throw new IOException("This is my IOException");
+ }
+
+ return "home";
+ }
+
+}
diff --git a/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/beans/User.java b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/beans/User.java
new file mode 100644
index 0000000..d564f10
--- /dev/null
+++ b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/beans/User.java
@@ -0,0 +1,27 @@
+/**
+ * Copyright 2012 Marin Solutions
+ */
+package com.captaindebug.spring_3_2.controleradvice.beans;
+
+/**
+ * User Bean
+ */
+public class User {
+
+ private final String firstName;
+ private final String surname;
+
+ public User(String firstName, String surname) {
+ super();
+ this.firstName = firstName;
+ this.surname = surname;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public String getSurname() {
+ return surname;
+ }
+}
diff --git a/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/dao/UserDao.java b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/dao/UserDao.java
new file mode 100644
index 0000000..f9b3118
--- /dev/null
+++ b/spring-3.2/src/main/java/com/captaindebug/spring_3_2/controleradvice/dao/UserDao.java
@@ -0,0 +1,21 @@
+/**
+ * Copyright 2012 Marin Solutions
+ */
+package com.captaindebug.spring_3_2.controleradvice.dao;
+
+import org.springframework.stereotype.Component;
+
+import com.captaindebug.spring_3_2.controleradvice.beans.User;
+
+/**
+ * @author Roger
+ *
+ */
+@Component
+public class UserDao {
+
+ public User readUserName() {
+ return new User("Joe", "Black");
+ }
+
+}
diff --git a/spring-3.2/src/main/resources/log4j.xml b/spring-3.2/src/main/resources/log4j.xml
new file mode 100644
index 0000000..6b98765
--- /dev/null
+++ b/spring-3.2/src/main/resources/log4j.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-3.2/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/spring-3.2/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
new file mode 100644
index 0000000..4624e6e
--- /dev/null
+++ b/spring-3.2/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-3.2/src/main/webapp/WEB-INF/spring/root-context.xml b/spring-3.2/src/main/webapp/WEB-INF/spring/root-context.xml
new file mode 100644
index 0000000..f7a30f0
--- /dev/null
+++ b/spring-3.2/src/main/webapp/WEB-INF/spring/root-context.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/spring-3.2/src/main/webapp/WEB-INF/views/error.jsp b/spring-3.2/src/main/webapp/WEB-INF/views/error.jsp
new file mode 100644
index 0000000..b322bcb
--- /dev/null
+++ b/spring-3.2/src/main/webapp/WEB-INF/views/error.jsp
@@ -0,0 +1,17 @@
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ page session="false" %>
+
+
+ Codestin Search App
+
+
+
+ Some Exceptional Exceptions
+
+
+
Well , there seems to have been an and
+we've lost all your important details. Hard luck, please try again.