public void apply( ServerTransaction txn, Map objects, BackReferences includeIDs, ObjectInstanceMonitor instanceMonitor) { final ServerTransactionID stxnID = txn.getServerTransactionID(); final ChannelID channelID = txn.getChannelID(); final TransactionID txnID = txn.getTransactionID(); final List changes = txn.getChanges(); GlobalTransactionID gtxID = txn.getGlobalTransactionID(); boolean active = isActive(); for (Iterator i = changes.iterator(); i.hasNext(); ) { DNA orgDNA = (DNA) i.next(); long version = orgDNA.getVersion(); if (version == DNA.NULL_VERSION) { Assert.assertFalse(gtxID.isNull()); version = gtxID.toLong(); } DNA change = new VersionizedDNAWrapper(orgDNA, version, true); ManagedObject mo = (ManagedObject) objects.get(change.getObjectID()); mo.apply(change, txnID, includeIDs, instanceMonitor, !active); if (active && !change.isDelta()) { // Only New objects reference are added here stateManager.addReference(txn.getChannelID(), mo.getID()); } } Map newRoots = txn.getNewRoots(); if (newRoots.size() > 0) { for (Iterator i = newRoots.entrySet().iterator(); i.hasNext(); ) { Entry entry = (Entry) i.next(); String rootName = (String) entry.getKey(); ObjectID newID = (ObjectID) entry.getValue(); objectManager.createRoot(rootName, newID); } } if (active) { channelStats.notifyTransaction(channelID); } transactionRateCounter.increment(); fireTransactionAppliedEvent(stxnID); }
@Before public void setUp() throws Exception { // Mocks ServerManagementContext smCtxt = Mockito.mock(ServerManagementContext.class, Mockito.RETURNS_MOCKS); ClientHandshakeAckMessage msg = mock(ClientHandshakeAckMessage.class); final MessageChannelInternal channel = mock(MessageChannelInternal.class); ChannelManager chMgr = mock(ChannelManager.class); ChannelStats stats = mock(ChannelStats.class); final ArgumentCaptor<ChannelID> cidCollector = ArgumentCaptor.forClass(ChannelID.class); when(channel.getChannelID()) .then( new Answer<ChannelID>() { @Override public ChannelID answer(InvocationOnMock invocation) throws Throwable { return cidCollector.getValue(); } }); final ArgumentCaptor<ChannelManagerEventListener> lsnrCaptor = ArgumentCaptor.forClass(ChannelManagerEventListener.class); Mockito.doNothing().when(chMgr).addEventListener(lsnrCaptor.capture()); when(channel.getRemoteAddress()).thenReturn(new TCSocketAddress(8192)); when(channel.createMessage(TCMessageType.CLIENT_HANDSHAKE_ACK_MESSAGE)).thenReturn(msg); when(chMgr.getChannel(cidCollector.capture())).thenReturn(channel); when(msg.getChannel()).thenReturn(channel); channelMgrMbean = new DSOChannelManagerImpl(chMgr, mock(TCConnectionManager.class), "1.0"); Mockito.doAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { lsnrCaptor.getValue().channelRemoved(channel); return null; } }) .when(channel) .close(); when(smCtxt.getChannelManager()).thenReturn((DSOChannelManagerMBean) channelMgrMbean); when(stats.getCounter(Matchers.same(channel), Matchers.startsWith("serverMap"))) .thenReturn(mock(SampledCumulativeCounter.class)); when(stats.getCounter( Matchers.same(channel), Matchers.argThat( new ArgumentMatcher<String>() { @Override public boolean matches(Object argument) { // Ugly, ugly, ugly String str = (String) argument; return !str.startsWith("serverMap"); } }))) .thenReturn(SampledCounter.NULL_SAMPLED_COUNTER); when(smCtxt.getChannelStats()).thenReturn(stats); mbeanSvr = mock(MBeanServer.class); dso = new DSO( smCtxt, mock(ServerConfigurationContext.class), mbeanSvr, mock(TerracottaOperatorEventHistoryProvider.class)); }