import akka.actor.ActorRef;
import akka.actor.Props;
+import akka.event.Logging;
import akka.testkit.JavaTestKit;
+import junit.framework.Assert;
import org.junit.Test;
import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChain;
import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChainReply;
+import org.opendaylight.controller.cluster.datastore.messages.EnableNotification;
import org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved;
import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener;
import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListenerReply;
import java.util.HashMap;
import java.util.Map;
+import static junit.framework.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
getSystem().actorOf(props, "testCreateTransactionChain");
- // Wait for Shard to become a Leader
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ // Wait for a specific log message to show up
+ final boolean result =
+ new JavaTestKit.EventFilter<Boolean>(Logging.Info.class
+ ) {
+ protected Boolean run() {
+ return true;
+ }
+ }.from(subject.path().toString())
+ .message("Switching from state Candidate to Leader")
+ .occurrences(1).exec();
+
+ Assert.assertEquals(true, result);
new Within(duration("1 seconds")) {
protected void run() {
subject.tell(new CreateTransactionChain().toSerializable(), getRef());
- final String out = new ExpectMsg<String>("match hint") {
+ final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
// do not put code outside this method, will run afterwards
protected String match(Object in) {
if (in.getClass().equals(CreateTransactionChainReply.SERIALIZABLE_CLASS)){
getRef());
subject.tell(new RegisterChangeListener(TestModel.TEST_PATH,
- getRef().path(), AsyncDataBroker.DataChangeScope.BASE).toSerializable(),
+ getRef().path(), AsyncDataBroker.DataChangeScope.BASE),
getRef());
- final String out = new ExpectMsg<String>("match hint") {
+ final Boolean notificationEnabled = new ExpectMsg<Boolean>("enable notification") {
+ // do not put code outside this method, will run afterwards
+ protected Boolean match(Object in) {
+ if(in instanceof EnableNotification){
+ return ((EnableNotification) in).isEnabled();
+ } else {
+ throw noMatch();
+ }
+ }
+ }.get(); // this extracts the received message
+
+ assertFalse(notificationEnabled);
+
+ final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
// do not put code outside this method, will run afterwards
protected String match(Object in) {
- if (in.getClass().equals(RegisterChangeListenerReply.SERIALIZABLE_CLASS)) {
+ if (in.getClass().equals(RegisterChangeListenerReply.class)) {
RegisterChangeListenerReply reply =
- RegisterChangeListenerReply.fromSerializable(getSystem(),in);
+ (RegisterChangeListenerReply) in;
return reply.getListenerRegistrationPath()
.toString();
} else {
assertTrue(out.matches(
"akka:\\/\\/test\\/user\\/testRegisterChangeListener\\/\\$.*"));
- // Will wait for the rest of the 3 seconds
- expectNoMsg();
}
getSystem().actorOf(props, "testCreateTransaction");
- // Wait for Shard to become a Leader
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ // Wait for a specific log message to show up
+ final boolean result =
+ new JavaTestKit.EventFilter<Boolean>(Logging.Info.class
+ ) {
+ protected Boolean run() {
+ return true;
+ }
+ }.from(subject.path().toString())
+ .message("Switching from state Candidate to Leader")
+ .occurrences(1).exec();
+ Assert.assertEquals(true, result);
new Within(duration("1 seconds")) {
protected void run() {
new UpdateSchemaContext(TestModel.createTestContext()),
getRef());
- subject.tell(new CreateTransaction("txn-1").toSerializable(),
+ subject.tell(new CreateTransaction("txn-1", TransactionProxy.TransactionType.READ_ONLY.ordinal() ).toSerializable(),
getRef());
- final String out = new ExpectMsg<String>("match hint") {
+ final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
// do not put code outside this method, will run afterwards
protected String match(Object in) {
if (in instanceof CreateTransactionReply) {