01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.persistence.impl;
06:
07: import com.tc.l2.ha.L2HADisabledCooridinator;
08: import com.tc.objectserver.api.TestSink;
09: import com.tc.objectserver.core.impl.TestServerConfigurationContext;
10: import com.tc.objectserver.handler.GlobalTransactionIDBatchRequestHandler;
11: import com.tc.objectserver.handler.GlobalTransactionIDBatchRequestHandler.GlobalTransactionIDBatchRequestContext;
12: import com.tc.test.TCTestCase;
13: import com.tc.util.concurrent.NoExceptionLinkedQueue;
14: import com.tc.util.sequence.BatchSequenceReceiver;
15:
16: public class GlobalTransactionIDBatchRequestHandlerTest extends
17: TCTestCase {
18:
19: private GlobalTransactionIDBatchRequestHandler provider;
20: private TestBatchSequenceReceiver receiver;
21: private TestMutableSequence persistentSequence;
22: private TestSink requestBatchSink;
23:
24: public void setUp() throws Exception {
25: persistentSequence = new TestMutableSequence();
26: requestBatchSink = new TestSink();
27:
28: provider = new GlobalTransactionIDBatchRequestHandler(
29: persistentSequence);
30: provider.setRequestBatchSink(requestBatchSink);
31:
32: TestServerConfigurationContext scc = new TestServerConfigurationContext();
33: scc.l2Coordinator = new L2HADisabledCooridinator();
34: provider.initializeContext(scc);
35:
36: receiver = new TestBatchSequenceReceiver();
37: }
38:
39: public void testx() throws Exception {
40: int batchSize = 5;
41: // make sure that the request context gets put in the sink properly.
42: provider.requestBatch(receiver, batchSize);
43: GlobalTransactionIDBatchRequestContext ctxt = (GlobalTransactionIDBatchRequestContext) requestBatchSink
44: .getInternalQueue().remove(0);
45: assertTrue(requestBatchSink.getInternalQueue().isEmpty());
46: assertSame(receiver, ctxt.getReceiver());
47: assertEquals(batchSize, ctxt.getBatchSize());
48:
49: // now check the handler interface to make sure it handles the request properly
50: provider.handleEvent(ctxt);
51:
52: // make sure it called the right thing on the sequence
53: Object[] args = (Object[]) persistentSequence.nextBatchQueue
54: .poll(1);
55: assertEquals(new Integer(batchSize), args[0]);
56:
57: // make sure it called back on the receiver
58: args = (Object[]) receiver.nextBatchQueue.poll(1);
59: assertEquals(new Long(persistentSequence.sequence - batchSize),
60: args[0]);
61: assertEquals(new Long(persistentSequence.sequence), args[1]);
62: }
63:
64: private static final class TestBatchSequenceReceiver implements
65: BatchSequenceReceiver {
66:
67: public final NoExceptionLinkedQueue nextBatchQueue = new NoExceptionLinkedQueue();
68:
69: public void setNextBatch(long start, long end) {
70: nextBatchQueue.put(new Object[] { new Long(start),
71: new Long(end) });
72: }
73:
74: public boolean hasNext() {
75: return true;
76: }
77:
78: }
79: }
|