use of org.apache.cxf.ws.rm.DestinationSequence in project cxf by apache.
the class RMTxStoreTestBase method testCreateSequenceStoreInboundMessage.
@Test
public void testCreateSequenceStoreInboundMessage() throws SQLException, IOException {
Identifier sid1 = null;
try {
DestinationSequence seq = control.createMock(DestinationSequence.class);
sid1 = new Identifier();
sid1.setValue("sequence1");
EndpointReferenceType epr = RMUtils.createAnonymousReference();
EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
EasyMock.expect(seq.getAcksTo()).andReturn(epr);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
store.createDestinationSequence(seq);
Collection<DestinationSequence> seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
assertEquals(1, seqs.size());
DestinationSequence rseq = seqs.iterator().next();
assertFalse(rseq.isAcknowledged(1));
Collection<RMMessage> in = store.getMessages(sid1, false);
assertEquals(0, in.size());
control.reset();
EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
EasyMock.expect(seq.getAcknowledgment()).andReturn(ack1);
EasyMock.expect(seq.getAcksTo()).andReturn(epr);
setupInboundMessage(seq, 1L, null);
in = store.getMessages(sid1, false);
assertEquals(1, in.size());
checkRecoveredMessages(in);
seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
assertEquals(1, seqs.size());
rseq = seqs.iterator().next();
assertTrue(rseq.isAcknowledged(1));
assertFalse(rseq.isAcknowledged(10));
EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
EasyMock.expect(seq.getAcknowledgment()).andReturn(ack2);
EasyMock.expect(seq.getAcksTo()).andReturn(epr);
control.replay();
store.persistIncoming(seq, null);
control.reset();
seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
assertEquals(1, seqs.size());
rseq = seqs.iterator().next();
assertTrue(rseq.isAcknowledged(10));
} finally {
if (null != sid1) {
store.removeDestinationSequence(sid1);
}
Collection<Long> msgNrs = new ArrayList<>();
msgNrs.add(ONE);
store.removeMessages(sid1, msgNrs, false);
}
}
use of org.apache.cxf.ws.rm.DestinationSequence in project cxf by apache.
the class RMTxStoreTestBase method testCreateDeleteDestSequences.
@Test
public void testCreateDeleteDestSequences() {
DestinationSequence seq = control.createMock(DestinationSequence.class);
Identifier sid1 = new Identifier();
sid1.setValue("sequence1");
EndpointReferenceType epr = RMUtils.createAnonymousReference();
EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
EasyMock.expect(seq.getAcksTo()).andReturn(epr);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
store.createDestinationSequence(seq);
control.verify();
control.reset();
EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
EasyMock.expect(seq.getAcksTo()).andReturn(epr);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
try {
store.createDestinationSequence(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);
epr = RMUtils.createReference(NON_ANON_ACKS_TO);
EasyMock.expect(seq.getAcksTo()).andReturn(epr);
EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
control.replay();
store.createDestinationSequence(seq);
control.verify();
store.removeDestinationSequence(sid1);
store.removeDestinationSequence(sid2);
// deleting once again is a no-op
store.removeDestinationSequence(sid2);
}
use of org.apache.cxf.ws.rm.DestinationSequence in project cxf by apache.
the class RMTxStore method getDestinationSequence.
public DestinationSequence getDestinationSequence(Identifier sid) {
if (LOG.isLoggable(Level.FINE)) {
LOG.info("Getting destination sequence for id: " + sid);
}
Connection con = verifyConnection();
PreparedStatement stmt = null;
SQLException conex = null;
ResultSet res = null;
try {
stmt = getStatement(con, SELECT_DEST_SEQUENCE_STMT_STR);
stmt.setString(1, sid.getValue());
res = stmt.executeQuery();
if (res.next()) {
EndpointReferenceType acksTo = RMUtils.createReference(res.getString(1));
long lm = res.getLong(2);
ProtocolVariation pv = decodeProtocolVersion(res.getString(3));
boolean t = res.getBoolean(4);
InputStream is = res.getBinaryStream(5);
SequenceAcknowledgement ack = null;
if (null != is) {
ack = PersistenceUtils.getInstance().deserialiseAcknowledgment(is);
}
return new DestinationSequence(sid, acksTo, lm, t, ack, pv);
}
} catch (SQLException ex) {
conex = ex;
LOG.log(Level.WARNING, new Message("SELECT_DEST_SEQ_FAILED_MSG", LOG).toString(), ex);
} finally {
releaseResources(stmt, res);
updateConnectionState(con, conex);
}
return null;
}
use of org.apache.cxf.ws.rm.DestinationSequence in project cxf by apache.
the class RMTxStore method getDestinationSequences.
public Collection<DestinationSequence> getDestinationSequences(String endpointIdentifier) {
if (LOG.isLoggable(Level.FINE)) {
LOG.info("Getting destination sequences for endpoint: " + endpointIdentifier);
}
Connection con = verifyConnection();
PreparedStatement stmt = null;
SQLException conex = null;
Collection<DestinationSequence> seqs = new ArrayList<>();
ResultSet res = null;
try {
stmt = getStatement(con, SELECT_DEST_SEQUENCES_STMT_STR);
stmt.setString(1, endpointIdentifier);
res = stmt.executeQuery();
while (res.next()) {
Identifier sid = new Identifier();
sid.setValue(res.getString(1));
EndpointReferenceType acksTo = RMUtils.createReference(res.getString(2));
long lm = res.getLong(3);
ProtocolVariation pv = decodeProtocolVersion(res.getString(4));
boolean t = res.getBoolean(5);
InputStream is = res.getBinaryStream(6);
SequenceAcknowledgement ack = null;
if (null != is) {
ack = PersistenceUtils.getInstance().deserialiseAcknowledgment(is);
}
DestinationSequence seq = new DestinationSequence(sid, acksTo, lm, t, ack, pv);
seqs.add(seq);
}
} catch (SQLException ex) {
conex = ex;
LOG.log(Level.WARNING, new Message("SELECT_DEST_SEQ_FAILED_MSG", LOG).toString(), ex);
} finally {
releaseResources(stmt, res);
updateConnectionState(con, conex);
}
return seqs;
}
use of org.apache.cxf.ws.rm.DestinationSequence in project cxf by apache.
the class AbstractClientPersistenceTest method verifyRecovery.
void verifyRecovery() throws Exception {
RMManager manager = bus.getExtension(RMManager.class);
assertNotNull(manager);
RMStore store = manager.getStore();
assertNotNull(store);
Client client = ClientProxy.getClient(greeter);
String id = RMUtils.getEndpointIdentifier(client.getEndpoint());
Collection<DestinationSequence> dss = store.getDestinationSequences(id);
assertEquals(1, dss.size());
Collection<SourceSequence> sss = store.getSourceSequences(id);
assertEquals(1, sss.size());
int i = 0;
while (store.getMessages(sss.iterator().next().getIdentifier(), true).size() > 0 && i < 10) {
Thread.sleep(200);
i++;
}
assertEquals(0, store.getMessages(sss.iterator().next().getIdentifier(), true).size());
assertEquals(0, store.getMessages(sss.iterator().next().getIdentifier(), false).size());
}
Aggregations