Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 620   Methods: 17
NCLOC: 453   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RemoteCacheListenerTest.java 82.4% 98.9% 100% 97.5%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source.
 3    * Copyright 2006, Red Hat Middleware LLC, and individual contributors
 4    * as indicated by the @author tags. See the copyright.txt file in the
 5    * distribution for a full listing of individual contributors.
 6    *
 7    * This is free software; you can redistribute it and/or modify it
 8    * under the terms of the GNU Lesser General Public License as
 9    * published by the Free Software Foundation; either version 2.1 of
 10    * the License, or (at your option) any later version.
 11    *
 12    * This software is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15    * Lesser General Public License for more details.
 16    *
 17    * You should have received a copy of the GNU Lesser General Public
 18    * License along with this software; if not, write to the Free
 19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21    */
 22   
 23    package org.jboss.cache.notifications;
 24   
 25    import junit.framework.TestCase;
 26    import org.jboss.cache.Cache;
 27    import org.jboss.cache.DefaultCacheFactory;
 28    import org.jboss.cache.Fqn;
 29    import org.jboss.cache.Node;
 30    import org.jboss.cache.config.Configuration;
 31    import org.jboss.cache.lock.IsolationLevel;
 32    import org.jboss.cache.notifications.event.Event;
 33    import static org.jboss.cache.notifications.event.Event.Type.*;
 34    import org.jboss.cache.notifications.event.EventImpl;
 35    import static org.jboss.cache.notifications.event.NodeModifiedEvent.ModificationType.*;
 36   
 37    import javax.transaction.Transaction;
 38    import javax.transaction.TransactionManager;
 39    import java.util.ArrayList;
 40    import java.util.Collections;
 41    import java.util.HashMap;
 42    import java.util.LinkedList;
 43    import java.util.List;
 44    import java.util.Map;
 45   
 46    /**
 47    * Remote conterpart of CacheListenerTest. Main difference is event is originating as local.
 48    *
 49    * @since 2.0.0
 50    */
 51    public class RemoteCacheListenerTest extends TestCase
 52    {
 53   
 54    protected boolean optLocking = false;
 55   
 56    private Cache cache1, cache2;
 57    private TransactionManager tm1, tm2;
 58    private EventLog eventLog1 = new EventLog(), eventLog2 = new EventLog();
 59    private Fqn fqn = Fqn.fromString("/test");
 60   
 61  24 protected void setUp() throws Exception
 62    {
 63  24 super.setUp();
 64  24 Configuration c = new Configuration();
 65  24 c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
 66  24 c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
 67  12 if (optLocking) c.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
 68  24 c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
 69  24 c.setFetchInMemoryState(false);
 70   
 71    // we need this because notifications emitted by the notification interceptor are done during the commit call.
 72    // If we want to check notifications on remote nodes we need to make sure the commit completes before we test anything.
 73  24 c.setSyncCommitPhase(true);
 74   
 75    // more time to help with debugging
 76  24 c.setSyncReplTimeout(60000);
 77   
 78  24 cache1 = DefaultCacheFactory.getInstance().createCache(c);
 79  24 cache2 = DefaultCacheFactory.getInstance().createCache(c.clone());
 80   
 81  24 eventLog1.events.clear();
 82  24 eventLog2.events.clear();
 83   
 84  24 cache1.addCacheListener(eventLog1);
 85  24 cache2.addCacheListener(eventLog2);
 86   
 87  24 tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
 88  24 tm2 = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
 89    }
 90   
 91  24 protected void tearDown() throws Exception
 92    {
 93  24 super.tearDown();
 94  24 TransactionManager tm;
 95  ? if ((tm = cache1.getConfiguration().getRuntimeConfig().getTransactionManager()) != null)
 96    {
 97  24 if (tm.getTransaction() != null)
 98    {
 99  0 try
 100    {
 101  0 tm.rollback();
 102    }
 103    catch (Exception e)
 104    {
 105    // do nothing
 106    }
 107    }
 108    }
 109  ? if ((tm = cache2.getConfiguration().getRuntimeConfig().getTransactionManager()) != null)
 110    {
 111  24 if (tm.getTransaction() != null)
 112    {
 113  0 try
 114    {
 115  0 tm.rollback();
 116    }
 117    catch (Exception e)
 118    {
 119    // do nothing
 120    }
 121    }
 122    }
 123   
 124  24 cache1.stop();
 125  24 cache1.destroy();
 126  24 cache2.stop();
 127  24 cache2.destroy();
 128    }
 129   
 130    // simple tests first
 131   
 132  2 public void testCreation() throws Exception
 133    {
 134  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 135  2 cache1.put(fqn, "key", "value");
 136  2 Map data = new HashMap();
 137  2 data.put("key", "value");
 138   
 139    //expectedRemote
 140  2 List<Event> expected = new ArrayList<Event>();
 141   
 142  2 if (optLocking)
 143  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
 144  2 expected.add(new EventImpl(true, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
 145  2 expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
 146  2 expected.add(new EventImpl(true, cache1, PUT_DATA, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_MODIFIED));
 147  2 expected.add(new EventImpl(false, cache1, PUT_DATA, data, fqn, null, true, null, false, null, NODE_MODIFIED));
 148  2 if (optLocking)
 149    {
 150  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
 151  1 eventLog1.scrubImplicitTransactions();
 152  1 eventLog2.scrubImplicitTransactions();
 153    }
 154   
 155  2 assertEquals("Local events not as expected", expected, eventLog1.events);
 156   
 157    //expectedRemote
 158  2 setCache(cache2, expected);
 159  2 markOriginRemote(expected);
 160   
 161  2 assertEquals("Remote events not as expected", expected, eventLog2.events);
 162  2 assertEquals("value", cache1.get(fqn, "key"));
 163    }
 164   
 165  2 public void testOnlyModification() throws Exception
 166    {
 167  2 assertNull(cache1.get(fqn, "key"));
 168  2 assertNull(cache2.get(fqn, "key"));
 169   
 170  2 cache1.put(fqn, "key", "value");
 171  2 Map oldData = new HashMap();
 172  2 oldData.put("key", "value");
 173   
 174  2 assertEquals("value", cache1.get(fqn, "key"));
 175  2 assertEquals("value", cache2.get(fqn, "key"));
 176   
 177    // clear event log
 178  2 eventLog1.events.clear();
 179  2 eventLog2.events.clear();
 180  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
 181  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 182   
 183    // modify existing node
 184  2 cache1.put(fqn, "key", "value2");
 185  2 Map newData = new HashMap();
 186  2 newData.put("key", "value2");
 187   
 188   
 189  2 List<Event> expected = new ArrayList<Event>();
 190  2 if (optLocking)
 191  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
 192  2 expected.add(new EventImpl(true, cache1, PUT_DATA, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
 193  2 expected.add(new EventImpl(false, cache1, PUT_DATA, newData, fqn, null, true, null, false, null, NODE_MODIFIED));
 194  2 if (optLocking)
 195    {
 196  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
 197  1 eventLog1.scrubImplicitTransactions();
 198  1 eventLog2.scrubImplicitTransactions();
 199    }
 200   
 201  2 assertEquals("Local events not as expected", expected, eventLog1.events);
 202   
 203    //expectedRemote
 204  2 setCache(cache2, expected);
 205  2 markOriginRemote(expected);
 206   
 207  2 assertEquals("Remote events not as expected", expected, eventLog2.events);
 208    }
 209   
 210   
 211  2 public void testOnlyRemoval() throws Exception
 212    {
 213  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 214  2 cache1.put(fqn, "key", "value");
 215  2 Map oldData = new HashMap();
 216  2 oldData.put("key", "value");
 217   
 218  2 assertEquals("value", cache1.get(fqn, "key"));
 219  2 assertEquals("value", cache2.get(fqn, "key"));
 220   
 221    // clear event log
 222  2 eventLog1.events.clear();
 223  2 eventLog2.events.clear();
 224  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
 225  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 226   
 227    // modify existing node
 228  2 cache1.removeNode(fqn);
 229   
 230  2 List<Event> expected = new ArrayList<Event>();
 231  2 if (optLocking)
 232  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
 233  2 expected.add(new EventImpl(true, cache1, null, oldData, fqn, null, true, null, false, null, NODE_REMOVED));
 234  2 expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, null, false, null, NODE_REMOVED));
 235  2 if (optLocking)
 236    {
 237  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
 238  1 eventLog1.scrubImplicitTransactions();
 239  1 eventLog2.scrubImplicitTransactions();
 240    }
 241   
 242  2 assertEquals("Local events not as expected", expected, eventLog1.events);
 243   
 244    //expectedRemote
 245  2 setCache(cache2, expected);
 246  2 markOriginRemote(expected);
 247   
 248  2 assertEquals("Remote events not as expected", expected, eventLog2.events);
 249   
 250    // test that the node has in fact been removed.
 251  2 assertNull("Should be null", cache1.getRoot().getChild(fqn));
 252  2 assertNull("Should be null", cache2.getRoot().getChild(fqn));
 253    }
 254   
 255   
 256  2 public void testRemoveData() throws Exception
 257    {
 258  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 259  2 cache1.put(fqn, "key", "value");
 260  2 cache1.put(fqn, "key2", "value2");
 261  2 Map oldData = new HashMap();
 262  2 oldData.put("key", "value");
 263  2 oldData.put("key2", "value2");
 264   
 265    // clear event log
 266  2 eventLog1.events.clear();
 267  2 eventLog2.events.clear();
 268  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
 269  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 270   
 271    // modify existing node
 272  2 cache1.remove(fqn, "key2");
 273  2 Map removed = new HashMap();
 274  2 removed.put("key2", "value2");
 275   
 276  2 List<Event> expected = new ArrayList<Event>();
 277  2 if (optLocking)
 278  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
 279  2 expected.add(new EventImpl(true, cache1, REMOVE_DATA, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
 280  2 expected.add(new EventImpl(false, cache1, REMOVE_DATA, removed, fqn, null, true, null, false, null, NODE_MODIFIED));
 281  2 if (optLocking)
 282    {
 283  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
 284  1 eventLog1.scrubImplicitTransactions();
 285  1 eventLog2.scrubImplicitTransactions();
 286    }
 287   
 288  2 assertEquals("Local events not as expected", expected, eventLog1.events);
 289   
 290    //expectedRemote
 291  2 setCache(cache2, expected);
 292  2 markOriginRemote(expected);
 293   
 294  2 assertEquals("Remote events not as expected", expected, eventLog2.events);
 295    }
 296   
 297  2 public void testPutMap() throws Exception
 298    {
 299  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 300  2 Map oldData = new HashMap();
 301  2 oldData.put("key", "value");
 302  2 oldData.put("key2", "value2");
 303   
 304  2 assertNull(cache1.getRoot().getChild(fqn));
 305  2 assertNull(cache2.getRoot().getChild(fqn));
 306   
 307    // clear event log
 308  2 eventLog1.events.clear();
 309  2 eventLog2.events.clear();
 310  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
 311  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 312   
 313  2 cache1.put(fqn, oldData);
 314   
 315  2 List<Event> expected = new ArrayList<Event>();
 316  2 if (optLocking)
 317  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
 318  2 expected.add(new EventImpl(true, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
 319  2 expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, null, false, null, NODE_CREATED));
 320  2 expected.add(new EventImpl(true, cache1, PUT_MAP, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_MODIFIED));
 321  2 expected.add(new EventImpl(false, cache1, PUT_MAP, oldData, fqn, null, true, null, false, null, NODE_MODIFIED));
 322  2 if (optLocking)
 323    {
 324  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
 325  1 eventLog1.scrubImplicitTransactions();
 326  1 eventLog2.scrubImplicitTransactions();
 327    }
 328   
 329  2 assertEquals("Local events not as expected", expected, eventLog1.events);
 330   
 331    //expectedRemote
 332  2 setCache(cache2, expected);
 333  2 markOriginRemote(expected);
 334   
 335  2 assertEquals("Remote events not as expected", expected, eventLog2.events);
 336    }
 337   
 338  2 public void testMove()
 339    {
 340  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 341  2 Fqn newParent = Fqn.fromString("/a");
 342  2 cache1.put(fqn, "key", "value");
 343  2 cache1.put(newParent, "key", "value");
 344   
 345  2 Node n1 = cache1.getRoot().getChild(fqn);
 346  2 Node n2 = cache1.getRoot().getChild(newParent);
 347   
 348  2 eventLog1.events.clear();
 349  2 eventLog2.events.clear();// clear events
 350  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
 351  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 352   
 353  2 cache1.move(n1.getFqn(), n2.getFqn());
 354  2 Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
 355   
 356   
 357  2 List<Event> expected = new ArrayList<Event>();
 358  2 if (optLocking)
 359  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
 360  2 expected.add(new EventImpl(true, cache1, null, null, fqn, null, true, newFqn, false, null, NODE_MOVED));
 361  2 expected.add(new EventImpl(false, cache1, null, null, fqn, null, true, newFqn, false, null, NODE_MOVED));
 362  2 if (optLocking)
 363    {
 364  1 expected.add(new EventImpl(false, cache1, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
 365  1 eventLog1.scrubImplicitTransactions();
 366  1 eventLog2.scrubImplicitTransactions();
 367    }
 368   
 369  2 assertEquals("Local events not as expected", expected, eventLog1.events);
 370   
 371    //expectedRemote
 372  2 setCache(cache2, expected);
 373  2 markOriginRemote(expected);
 374   
 375  2 assertEquals("Remote events not as expected", expected, eventLog2.events);
 376    }
 377   
 378    // -- now the transactional ones
 379   
 380  2 public void testTxCreationCommit() throws Exception
 381    {
 382  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 383  2 tm1.begin();
 384  2 Transaction tx = tm1.getTransaction();
 385  2 cache1.put(fqn, "key", "value");
 386  2 Map data = new HashMap();
 387  2 data.put("key", "value");
 388   
 389  2 List<Event> expected = new ArrayList<Event>();
 390  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
 391  2 expected.add(new EventImpl(true, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
 392  2 expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
 393  2 expected.add(new EventImpl(true, cache1, PUT_DATA, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_MODIFIED));
 394  2 expected.add(new EventImpl(false, cache1, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
 395   
 396  2 assertEquals(expected, eventLog1.events);
 397  2 assertTrue(eventLog2.events.isEmpty());
 398   
 399  2 tm1.commit();
 400   
 401  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
 402  2 assertEquals(expected, eventLog1.events);
 403   
 404  2 setCache(cache2, expected);
 405  2 markOriginRemote(expected);
 406  2 scrubTransactions(expected);
 407  2 eventLog2.scrubImplicitTransactions();
 408  2 assertEquals(expected, eventLog2.events);
 409   
 410  2 assertEquals("value", cache1.get(fqn, "key"));
 411  2 assertEquals("value", cache2.get(fqn, "key"));
 412    }
 413   
 414  2 public void testTxCreationRollback() throws Exception
 415    {
 416  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 417  2 tm1.begin();
 418  2 Transaction tx = tm1.getTransaction();
 419  2 cache1.put(fqn, "key", "value");
 420  2 Map data = new HashMap();
 421  2 data.put("key", "value");
 422  2 List<Event> expected = new ArrayList<Event>();
 423  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
 424  2 expected.add(new EventImpl(true, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
 425  2 expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
 426  2 expected.add(new EventImpl(true, cache1, PUT_DATA, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_MODIFIED));
 427  2 expected.add(new EventImpl(false, cache1, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
 428   
 429  2 assertEquals(expected, eventLog1.events);
 430  2 assertTrue(eventLog2.events.isEmpty());
 431  2 tm1.rollback();
 432   
 433  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_COMPLETED));
 434  2 assertEquals(expected, eventLog1.events);
 435  2 assertTrue(eventLog2.events.isEmpty());
 436   
 437  2 assertNull(cache1.get(fqn, "key"));
 438  2 assertNull(cache2.get(fqn, "key"));
 439    }
 440   
 441   
 442  2 public void testTxOnlyModification() throws Exception
 443    {
 444  2 assertNull(cache1.get(fqn, "key"));
 445  2 assertNull(cache2.get(fqn, "key"));
 446   
 447  2 cache1.put(fqn, "key", "value");
 448  2 Map oldData = new HashMap();
 449  2 oldData.put("key", "value");
 450   
 451  2 assertEquals("value", cache1.get(fqn, "key"));
 452  2 assertEquals("value", cache2.get(fqn, "key"));
 453   
 454    // clear event log
 455  2 eventLog1.events.clear();
 456  2 eventLog2.events.clear();
 457  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
 458  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 459   
 460    // modify existing node
 461  2 tm1.begin();
 462  2 Transaction tx = tm1.getTransaction();
 463  2 Map newData = new HashMap();
 464  2 newData.put("key", "value2");
 465  2 cache1.put(fqn, "key", "value2");
 466  2 List<Event> expected = new ArrayList<Event>();
 467  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
 468  2 expected.add(new EventImpl(true, cache1, PUT_DATA, oldData, fqn, tx, true, null, false, null, NODE_MODIFIED));
 469  2 expected.add(new EventImpl(false, cache1, PUT_DATA, newData, fqn, tx, true, null, false, null, NODE_MODIFIED));
 470  2 assertEquals(expected, eventLog1.events);
 471   
 472  2 assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
 473  2 tm1.commit();
 474   
 475  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
 476  2 assertEquals(expected, eventLog1.events);
 477   
 478  2 setCache(cache2, expected);
 479  2 markOriginRemote(expected);
 480  2 scrubTransactions(expected);
 481  2 eventLog2.scrubImplicitTransactions();
 482  2 assertEquals(expected, eventLog2.events);
 483    }
 484   
 485   
 486  2 public void testTxOnlyRemoval() throws Exception
 487    {
 488  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 489  2 cache1.put(fqn, "key", "value");
 490  2 Map oldData = new HashMap();
 491  2 oldData.put("key", "value");
 492   
 493  2 assertEquals("value", cache1.get(fqn, "key"));
 494  2 assertEquals("value", cache2.get(fqn, "key"));
 495   
 496    // clear event log
 497  2 eventLog1.events.clear();
 498  2 eventLog2.events.clear();
 499  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
 500  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 501   
 502    // modify existing node
 503  2 tm1.begin();
 504  2 Transaction tx = tm1.getTransaction();
 505  2 cache1.removeNode(fqn);
 506  2 List<Event> expected = new ArrayList<Event>();
 507  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
 508  2 expected.add(new EventImpl(true, cache1, null, oldData, fqn, tx, true, null, false, null, NODE_REMOVED));
 509  2 expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, null, false, null, NODE_REMOVED));
 510  2 assertEquals(expected, eventLog1.events);
 511  2 assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
 512  2 tm1.commit();
 513   
 514  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
 515  2 assertEquals(expected, eventLog1.events);
 516   
 517  2 setCache(cache2, expected);
 518  2 markOriginRemote(expected);
 519  2 scrubTransactions(expected);
 520  2 eventLog2.scrubImplicitTransactions();
 521  2 assertEquals(expected, eventLog2.events);
 522   
 523    // test that the node has in fact been removed.
 524  2 assertNull("Should be null", cache1.getRoot().getChild(fqn));
 525  2 assertNull("Should be null", cache2.getRoot().getChild(fqn));
 526    }
 527   
 528   
 529  2 public void testTxRemoveData() throws Exception
 530    {
 531  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 532  2 cache1.put(fqn, "key", "value");
 533  2 cache1.put(fqn, "key2", "value2");
 534  2 Map oldData = new HashMap();
 535  2 oldData.put("key", "value");
 536  2 oldData.put("key2", "value2");
 537   
 538    // clear event log
 539  2 eventLog1.events.clear();
 540  2 eventLog2.events.clear();
 541  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
 542  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 543   
 544    // modify existing node
 545  2 tm1.begin();
 546  2 Transaction tx = tm1.getTransaction();
 547  2 Map removed = new HashMap();
 548  2 removed.put("key2", "value2");
 549  2 cache1.remove(fqn, "key2");
 550  2 List<Event> expected = new LinkedList<Event>();
 551  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
 552  2 expected.add(new EventImpl(true, cache1, REMOVE_DATA, oldData, fqn, tx, true, null, false, null, NODE_MODIFIED));
 553  2 expected.add(new EventImpl(false, cache1, REMOVE_DATA, removed, fqn, tx, true, null, false, null, NODE_MODIFIED));
 554  2 assertEquals(expected, eventLog1.events);
 555  2 assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
 556  2 tm1.commit();
 557   
 558  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
 559  2 assertEquals(expected, eventLog1.events);
 560   
 561  2 setCache(cache2, expected);
 562  2 markOriginRemote(expected);
 563  2 scrubTransactions(expected);
 564  2 eventLog2.scrubImplicitTransactions();
 565  2 assertEquals(expected, eventLog2.events);
 566   
 567    }
 568   
 569  2 public void testTxMove() throws Exception
 570    {
 571  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 572  2 Fqn newParent = Fqn.fromString("/a");
 573  2 cache1.put(fqn, "key", "value");
 574  2 cache1.put(newParent, "key", "value");
 575   
 576  2 Node n1 = cache1.getRoot().getChild(fqn);
 577  2 Node n2 = cache1.getRoot().getChild(newParent);
 578   
 579  2 eventLog1.events.clear();
 580  2 eventLog2.events.clear();// clear events
 581  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog1.events);
 582  2 assertEquals("Event log should be empty", Collections.emptyList(), eventLog2.events);
 583   
 584  2 tm1.begin();
 585  2 Transaction tx = tm1.getTransaction();
 586  2 Fqn newFqn = new Fqn(newParent, fqn.getLastElement());
 587  2 cache1.move(n1.getFqn(), n2.getFqn());
 588  2 List<Event> expected = new ArrayList<Event>();
 589  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
 590  2 expected.add(new EventImpl(true, cache1, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
 591  2 expected.add(new EventImpl(false, cache1, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
 592  2 assertEquals(expected, eventLog1.events);
 593  2 assertEquals("Events log should be empty until commit time", 0, eventLog2.events.size());
 594  2 tm1.commit();
 595   
 596  2 expected.add(new EventImpl(false, cache1, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
 597  2 assertEquals(expected, eventLog1.events);
 598   
 599  2 setCache(cache2, expected);
 600  2 markOriginRemote(expected);
 601  2 scrubTransactions(expected);
 602  2 eventLog2.scrubImplicitTransactions();
 603  2 assertEquals(expected, eventLog2.events);
 604    }
 605   
 606  22 private void setCache(Cache c, List<Event> l)
 607    {
 608  88 for (Event e : l) ((EventImpl) e).setCache(c);
 609    }
 610   
 611  22 private void markOriginRemote(List<Event> l)
 612    {
 613  88 for (Event e : l) ((EventImpl) e).setOriginLocal(false);
 614    }
 615   
 616  10 private void scrubTransactions(List<Event> l)
 617    {
 618  44 for (Event e : l) ((EventImpl) e).setTransaction(null);
 619    }
 620    }