001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.objectserver.tx;
006:
007: import com.tc.test.TCTestCase;
008:
009: public class TransactionBatchManagerImplTest extends TCTestCase {
010:
011: public TransactionBatchManagerImplTest() {
012: super ();
013: }
014:
015: // private TransactionBatchManagerImpl mgr;
016: //
017: // protected void setUp() throws Exception {
018: // super.setUp();
019: // this.mgr = new TransactionBatchManagerImpl();
020: // }
021:
022: public void tests() throws Exception {
023: // ChannelID channelID1 = new ChannelID(1);
024: // TransactionID txID1 = new TransactionID(1);
025: // TxnBatchID batchID1 = new TxnBatchID(1);
026: //
027: // int count = 10;
028: //
029: // List batchDescriptors = new LinkedList();
030: // for (int i = 1; i <= 2; i++) {
031: // batchDescriptors.add(new BatchDescriptor(new ChannelID(i), new TxnBatchID(1), count));
032: // batchDescriptors.add(new BatchDescriptor(new ChannelID(i), new TxnBatchID(2), count));
033: // }
034: //
035: // // make sure that you can't call batchComponentComplete unless define batch has been called for that
036: // // batch already.
037: // try {
038: // mgr.batchComponentComplete(channelID1, batchID1, txID1);
039: // fail("Expected a NoSuchBatchException");
040: // } catch (NoSuchBatchException e) {
041: // // expected
042: // }
043: //
044: // // define batches
045: // for (Iterator i = batchDescriptors.iterator(); i.hasNext();) {
046: // defineBatchFor((BatchDescriptor) i.next());
047: // }
048: //
049: // // make sure that you can't define the same batch more than once
050: // for (Iterator i = batchDescriptors.iterator(); i.hasNext();) {
051: // try {
052: // defineBatchFor((BatchDescriptor) i.next());
053: // fail("Expected a BatchDefinedException");
054: // } catch (BatchDefinedException e) {
055: // // expected
056: // }
057: // }
058: //
059: // // call batchComponentComplete() until all the components are complete
060: // for (Iterator i = batchDescriptors.iterator(); i.hasNext();) {
061: // BatchDescriptor desc = (BatchDescriptor) i.next();
062: // for (int j = 1; j <= desc.count; j++) {
063: // boolean isComplete = j == desc.count;
064: // assertEquals(isComplete, mgr.batchComponentComplete(desc.channelID, desc.batchID, new TransactionID(j)));
065: // }
066: // }
067: //
068: // // XXX: This is a bit of a weird way to test this.
069: // // Now that the batches have been completed, you should be able to define them again
070: // for (Iterator i = batchDescriptors.iterator(); i.hasNext();) {
071: // defineBatchFor((BatchDescriptor) i.next());
072: // }
073: //
074: // // now kill a client
075: // BatchDescriptor desc = (BatchDescriptor) batchDescriptors.get(0);
076: // mgr.shutdownClient(desc.channelID);
077: // for (Iterator batchDesIter = batchDescriptors.iterator(); batchDesIter.hasNext();) {
078: // BatchDescriptor bd = (BatchDescriptor) batchDesIter.next();
079: // if (bd.channelID.equals(desc.channelID)) {
080: // for (int i = 1; i <= desc.count; i++) {
081: // // batchComponentComplete should never return true...
082: // assertFalse(mgr.batchComponentComplete(desc.channelID, desc.batchID, new TransactionID(i)));
083: // }
084: // }
085: // }
086: //
087: // // now calling batchComponentComplete on an undefined batch if the client has been killed should throw and
088: // exception
089: // for (int i = 1; i <= desc.count; i++) {
090: // try {
091: // mgr.batchComponentComplete(desc.channelID, desc.batchID, new TransactionID(i));
092: // fail("Expected a NoSuchBatchException");
093: // } catch (NoSuchBatchException e) {
094: // // expected
095: // }
096: // }
097: //
098: }
099: //
100: // private void defineBatchFor(BatchDescriptor desc) throws Exception {
101: // mgr.defineBatch(desc.channelID, desc.batchID, desc.count);
102: // }
103: //
104: // private final class BatchDescriptor {
105: // public final ChannelID channelID;
106: // public final TxnBatchID batchID;
107: // public final int count;
108: //
109: // private BatchDescriptor(ChannelID channelID, TxnBatchID batchID, int count) {
110: // this.channelID = channelID;
111: // this.batchID = batchID;
112: // this.count = count;
113: // }
114: // }
115:
116: }
|