use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.
the class RMTxStoreTestBase method testCreateSequenceStoreOutboundMessage.
@Test
public void testCreateSequenceStoreOutboundMessage() throws SQLException, IOException {
Identifier sid1 = null;
try {
SourceSequence seq = control.createMock(SourceSequence.class);
sid1 = new Identifier();
sid1.setValue("sequence1");
EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
EasyMock.expect(seq.getExpires()).andReturn(null);
EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
store.createSourceSequence(seq);
control.reset();
Collection<SourceSequence> seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
assertEquals(1, seqs.size());
SourceSequence rseq = seqs.iterator().next();
assertFalse(rseq.isLastMessage());
Collection<RMMessage> out = store.getMessages(sid1, true);
assertEquals(0, out.size());
// set the last message flag
EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
EasyMock.expect(seq.isLastMessage()).andReturn(true);
setupOutboundMessage(seq, 1L, null);
out = store.getMessages(sid1, true);
assertEquals(1, out.size());
checkRecoveredMessages(out);
// verify the updated sequence
seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
assertEquals(1, seqs.size());
rseq = seqs.iterator().next();
assertTrue(rseq.isLastMessage());
// set the last message flag
EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
EasyMock.expect(seq.getCurrentMessageNr()).andReturn(2L);
EasyMock.expect(seq.isLastMessage()).andReturn(true);
control.replay();
store.persistOutgoing(seq, null);
control.reset();
seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
assertEquals(1, seqs.size());
rseq = seqs.iterator().next();
assertEquals(2, rseq.getCurrentMessageNr());
} finally {
if (null != sid1) {
store.removeSourceSequence(sid1);
}
Collection<Long> msgNrs = new ArrayList<>();
msgNrs.add(ONE);
store.removeMessages(sid1, msgNrs, true);
}
}
use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.
the class RMTxStoreTestBase method checkRecoveredSourceSequences.
private void checkRecoveredSourceSequences(Collection<SourceSequence> seqs) {
for (SourceSequence recovered : seqs) {
assertTrue("sequence1".equals(recovered.getIdentifier().getValue()) || "sequence2".equals(recovered.getIdentifier().getValue()));
if ("sequence1".equals(recovered.getIdentifier().getValue())) {
assertFalse(recovered.isLastMessage());
assertEquals(1, recovered.getCurrentMessageNr());
assertNull(recovered.getExpires());
assertNull(recovered.getOfferingSequenceIdentifier());
assertEquals(ProtocolVariation.RM10WSA200408, recovered.getProtocol());
} else {
assertTrue(recovered.isLastMessage());
assertEquals(10, recovered.getCurrentMessageNr());
assertNotNull(recovered.getExpires());
assertEquals("offeringSequence", recovered.getOfferingSequenceIdentifier().getValue());
assertEquals(ProtocolVariation.RM11WSA200508, recovered.getProtocol());
}
}
}
use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.
the class RMTxStoreTestBase method testCreateDeleteSrcSequences.
@Test
public void testCreateDeleteSrcSequences() {
SourceSequence seq = control.createMock(SourceSequence.class);
Identifier sid1 = new Identifier();
sid1.setValue("sequence1");
EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
EasyMock.expect(seq.getExpires()).andReturn(null);
EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
store.createSourceSequence(seq);
control.verify();
control.reset();
EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
EasyMock.expect(seq.getExpires()).andReturn(null);
EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
try {
store.createSourceSequence(seq);
fail("Expected RMStoreException was not thrown.");
} catch (RMStoreException ex) {
SQLException se = (SQLException) ex.getCause();
// duplicate key value
assertEquals("23505", se.getSQLState());
}
control.verify();
control.reset();
Identifier sid2 = new Identifier();
sid2.setValue("sequence2");
EasyMock.expect(seq.getIdentifier()).andReturn(sid2);
EasyMock.expect(seq.getExpires()).andReturn(new Date());
Identifier sid3 = new Identifier();
sid3.setValue("offeringSequence3");
EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(sid3);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
store.createSourceSequence(seq);
control.verify();
store.removeSourceSequence(sid1);
store.removeSourceSequence(sid2);
// deleting once again is a no-op
store.removeSourceSequence(sid2);
}
use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.
the class RMTxStoreTestBase method setupSourceSequence.
private Identifier setupSourceSequence(String s) throws SQLException {
SourceSequence seq = control.createMock(SourceSequence.class);
Identifier sid = new Identifier();
sid.setValue(s);
Date expiry = null;
Identifier osid = null;
Long cmn = ONE;
boolean lm = false;
ProtocolVariation pv = ProtocolVariation.RM10WSA200408;
if ("sequence2".equals(s)) {
expiry = new Date(System.currentTimeMillis() + 3600 * 1000);
osid = new Identifier();
osid.setValue("offeringSequence");
cmn = TEN;
lm = true;
pv = ProtocolVariation.RM11WSA200508;
}
EasyMock.expect(seq.getIdentifier()).andReturn(sid);
EasyMock.expect(seq.getExpires()).andReturn(expiry);
EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(osid);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
EasyMock.expect(seq.getCurrentMessageNr()).andReturn(cmn);
EasyMock.expect(seq.isLastMessage()).andReturn(lm);
EasyMock.expect(seq.getIdentifier()).andReturn(sid);
EasyMock.expect(seq.getProtocol()).andReturn(pv);
control.replay();
store.createSourceSequence(seq);
Connection con = getConnection();
try {
store.beginTransaction();
store.updateSourceSequence(con, seq);
store.commit(con);
} finally {
releaseConnection(con);
}
control.reset();
return sid;
}
use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.
the class RMTxStoreTwoSchemasTest method testStoreIsolation.
@Test
public void testStoreIsolation() throws Exception {
SourceSequence seq = control.createMock(SourceSequence.class);
Identifier sid1 = new Identifier();
sid1.setValue("sequence1");
EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
EasyMock.expect(seq.getExpires()).andReturn(null);
EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
store1.createSourceSequence(seq);
control.verify();
SourceSequence rseq = store1.getSourceSequence(sid1);
assertNotNull(rseq);
rseq = store2.getSourceSequence(sid1);
assertNull(rseq);
control.reset();
EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
EasyMock.expect(seq.getExpires()).andReturn(null);
EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
store2.createSourceSequence(seq);
control.verify();
rseq = store2.getSourceSequence(sid1);
assertNotNull(rseq);
// create another store
RMTxStore store3 = createStore(null);
store3.init();
rseq = store3.getSourceSequence(sid1);
assertNull(rseq);
// switch to the store1's schema
store3.setSchemaName(store1.getSchemaName());
store3.init();
rseq = store3.getSourceSequence(sid1);
assertNotNull(rseq);
}
Aggregations