Source Code Cross Referenced for TransactionBatchAccountingTest.java in  » Net » Terracotta » com » tc » object » tx » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tc.object.tx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc.object.tx;
005:
006:        import EDU.oswego.cs.dl.util.concurrent.SynchronizedLong;
007:
008:        import java.util.Collections;
009:        import java.util.HashSet;
010:        import java.util.LinkedList;
011:        import java.util.List;
012:        import java.util.Set;
013:
014:        import junit.framework.TestCase;
015:
016:        public class TransactionBatchAccountingTest extends TestCase {
017:            private TransactionBatchAccounting acct;
018:            private Sequence sequence;
019:
020:            public void setUp() throws Exception {
021:                acct = new TransactionBatchAccounting();
022:                sequence = new Sequence();
023:            }
024:
025:            public void testBasics() throws Exception {
026:                final List incompleteBatchIDs = new LinkedList();
027:                // try adding an empty batch
028:                Batch batch1 = new Batch(new TxnBatchID(sequence.next()));
029:                acct.addBatch(batch1.batchID, batch1.transactionIDs);
030:                // there should be no incomplete batches
031:                assertEquals(Collections.EMPTY_LIST, acct
032:                        .addIncompleteBatchIDsTo(new LinkedList()));
033:                // the min incomplete batch id should be the null id.
034:                assertEquals(TxnBatchID.NULL_BATCH_ID, acct
035:                        .getMinIncompleteBatchID());
036:
037:                // try adding a batch with a two transactions
038:                TransactionID txID1 = new TransactionID(sequence.next());
039:                TransactionID txID2 = new TransactionID(sequence.next());
040:
041:                Batch batch2 = new Batch(new TxnBatchID(sequence.next()));
042:                batch2.addTransactionID(txID1);
043:                batch2.addTransactionID(txID2);
044:                incompleteBatchIDs.add(batch2.batchID);
045:                acct.addBatch(batch2.batchID, batch2.transactionIDs);
046:
047:                TransactionID txID3 = new TransactionID(sequence.next());
048:                Batch batch3 = new Batch(new TxnBatchID(sequence.next()));
049:                batch3.addTransactionID(txID3);
050:                incompleteBatchIDs.add(batch3.batchID);
051:                acct.addBatch(batch3.batchID, batch3.transactionIDs);
052:
053:                TransactionID txID4 = new TransactionID(sequence.next());
054:                Batch batch4 = new Batch(new TxnBatchID(sequence.next()));
055:                batch4.addTransactionID(txID4);
056:                incompleteBatchIDs.add(batch4.batchID);
057:                acct.addBatch(batch4.batchID, batch4.transactionIDs);
058:
059:                // LWM is the lowest txn id, since there were no acknowledgements
060:                assertEquals(txID1, acct.getLowWaterMark());
061:
062:                // check the incomplete batches
063:                assertEquals(incompleteBatchIDs, acct
064:                        .addIncompleteBatchIDsTo(new LinkedList()));
065:                assertEquals(incompleteBatchIDs.get(0), acct
066:                        .getMinIncompleteBatchID());
067:
068:                // ACK the first transaction in the multi-transaction batch
069:                assertEquals(TxnBatchID.NULL_BATCH_ID, acct.acknowledge(txID1));
070:                // there should still be no completed batches
071:                assertEquals(incompleteBatchIDs, acct
072:                        .addIncompleteBatchIDsTo(new LinkedList()));
073:
074:                //LWM moved up
075:                assertEquals(txID2, acct.getLowWaterMark());
076:
077:                // ACK the last transaction in the multi-transaction batch. This should cause that batch to become complete AND
078:                // cause all of its constituent transactions to become completed.
079:                assertEquals(batch2.batchID, acct.acknowledge(txID2));
080:                incompleteBatchIDs.remove(batch2.batchID);
081:                assertEquals(incompleteBatchIDs, acct
082:                        .addIncompleteBatchIDsTo(new LinkedList()));
083:                assertEquals(incompleteBatchIDs.get(0), acct
084:                        .getMinIncompleteBatchID());
085:
086:                //LWM moved up
087:                assertEquals(txID3, acct.getLowWaterMark());
088:
089:                // LWM remains the same
090:                assertEquals(txID3, acct.getLowWaterMark());
091:
092:                // ACK another transaction
093:                assertEquals(batch3.batchID, acct.acknowledge(txID3));
094:                incompleteBatchIDs.remove(batch3.batchID);
095:                assertEquals(incompleteBatchIDs, acct
096:                        .addIncompleteBatchIDsTo(new LinkedList()));
097:                assertEquals(incompleteBatchIDs.get(0), acct
098:                        .getMinIncompleteBatchID());
099:
100:                //LWM moved up
101:                assertEquals(txID4, acct.getLowWaterMark());
102:
103:                // ACK the last transaction
104:                assertEquals(batch4.batchID, acct.acknowledge(txID4));
105:                incompleteBatchIDs.remove(batch4.batchID);
106:                assertEquals(Collections.EMPTY_LIST, incompleteBatchIDs);
107:                assertEquals(incompleteBatchIDs, acct
108:                        .addIncompleteBatchIDsTo(new LinkedList()));
109:                assertEquals(TxnBatchID.NULL_BATCH_ID, acct
110:                        .getMinIncompleteBatchID());
111:
112:                //LWM moved up
113:                assertEquals(txID4.next(), acct.getLowWaterMark());
114:
115:            }
116:
117:            /**
118:             * Tests that the set of incomplete batch ids comes out in the same order it come in.
119:             */
120:            public void testBatchOrdering() throws Exception {
121:                List batchIDs = new LinkedList();
122:                for (int i = 0; i < 1000; i++) {
123:                    TxnBatchID batchID = new TxnBatchID(sequence.next());
124:                    Set transactionIDs = new HashSet();
125:                    for (int j = 0; j < 10; j++) {
126:                        transactionIDs.add(new TransactionID(sequence.next()));
127:                    }
128:                    acct.addBatch(batchID, transactionIDs);
129:                    batchIDs.add(batchID);
130:
131:                    assertEquals(batchIDs, acct
132:                            .addIncompleteBatchIDsTo(new LinkedList()));
133:                }
134:            }
135:
136:            private static final class Sequence {
137:                private SynchronizedLong sequence = new SynchronizedLong(0);
138:
139:                public long next() {
140:                    return sequence.increment();
141:                }
142:            }
143:
144:            private static final class Batch {
145:
146:                private final TxnBatchID batchID;
147:                private final Set transactionIDs = new HashSet();
148:
149:                public Batch(TxnBatchID batchID) {
150:                    this .batchID = batchID;
151:                }
152:
153:                public void addTransactionID(TransactionID txID) {
154:                    transactionIDs.add(txID);
155:                }
156:            }
157:
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.