use of org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedShort in project qpid-protonj2 by apache.
the class DriverSessions method handleBegin.
// ----- Process performatives that require session level tracking
public SessionTracker handleBegin(Begin remoteBegin, UnsignedShort remoteChannel) {
if (remoteSessions.containsKey(remoteChannel)) {
throw new AssertionError("Received duplicate Begin for already opened session on channel: " + remoteChannel);
}
final UnsignedShort localChannelMax = driver.getLocalOpen() == null ? UnsignedShort.ZERO : driver.getLocalOpen().getChannelMax() == null ? UnsignedShort.MAX_VALUE : driver.getLocalOpen().getChannelMax();
if (remoteChannel.compareTo(localChannelMax) > 0) {
throw new AssertionError("Channel Max [" + localChannelMax + "] Exceeded for session Begin: " + remoteChannel);
}
// Result that we need to update here once validation is complete.
final SessionTracker sessionTracker;
if (remoteBegin.getRemoteChannel() != null) {
// This should be a response to previous Begin that this test driver sent if there
// is a remote channel set in which case a local session should already have been
// created and if not that is an error
sessionTracker = localSessions.get(remoteBegin.getRemoteChannel());
if (sessionTracker == null) {
throw new AssertionError(String.format("Received Begin on channel [%s] that indicated it was a response to a Begin this driver never sent to channel [%s]: ", remoteChannel, remoteBegin.getRemoteChannel()));
}
} else {
// Remote has requested that the driver create a new session which will require a scripted
// response in order to complete the begin cycle. Start tracking now for future
sessionTracker = new SessionTracker(driver);
}
sessionTracker.handleBegin(remoteBegin, remoteChannel);
remoteSessions.put(remoteChannel, sessionTracker);
lastRemotelyOpenedSession = sessionTracker.getRemoteChannel();
return sessionTracker;
}
use of org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedShort in project qpid-protonj2 by apache.
the class DetachInjectAction method beforeActionPerformed.
@Override
protected void beforeActionPerformed(AMQPTestDriver driver) {
// won't attempt to make up one since we aren't sure what the intent here is.
if (onChannel() == CHANNEL_UNSET) {
if (driver.sessions().getLastLocallyOpenedSession() == null) {
throw new AssertionError("Scripted Action cannot run without a configured channel: " + "No locally opened session exists to auto select a channel.");
}
onChannel(driver.sessions().getLastLocallyOpenedSession().getLocalChannel().intValue());
}
final UnsignedShort localChannel = UnsignedShort.valueOf(onChannel());
final SessionTracker session = driver.sessions().getSessionFromLocalChannel(localChannel);
// of unexpected performatives so we just allow no session cases and send what we are told.
if (session != null) {
// be added to allow forcing the handle to be null for testing specification requirements.
if (detach.getHandle() == null) {
detach.setHandle(session.getLastOpenedLink().getHandle());
}
session.handleLocalDetach(detach);
}
}
use of org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedShort in project qpid-protonj2 by apache.
the class DetachExpectation method handleDetach.
// ----- Handle the performative and configure response is told to respond
@Override
public void handleDetach(int frameSize, Detach detach, ByteBuf payload, int channel, AMQPTestDriver context) {
super.handleDetach(frameSize, detach, payload, channel, context);
final UnsignedShort remoteChannel = UnsignedShort.valueOf(channel);
final SessionTracker session = driver.sessions().getSessionFromRemoteChannel(remoteChannel);
if (session == null) {
throw new AssertionError(String.format("Received Detach on channel [%s] that has no matching Session for that remote channel. ", remoteChannel));
}
final LinkTracker link = session.handleRemoteDetach(detach);
if (link == null) {
throw new AssertionError(String.format("Received Detach on channel [%s] that has no matching Attached link for that remote handle. ", detach.getHandle()));
}
if (response != null) {
// to say otherwise by the test.
if (response.onChannel() == BeginInjectAction.CHANNEL_UNSET) {
response.onChannel(link.getSession().getLocalChannel());
}
if (response.getPerformative().getHandle() == null) {
response.withHandle(link.getHandle());
}
if (response.getPerformative().getClosed() == null) {
response.withClosed(detach.getClosed());
}
}
}
use of org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedShort in project qpid-protonj2 by apache.
the class DispositionExpectation method handleDisposition.
// ----- Handle the incoming Disposition validation and update local side if able
@Override
public void handleDisposition(int frameSize, Disposition disposition, ByteBuf payload, int channel, AMQPTestDriver context) {
super.handleDisposition(frameSize, disposition, payload, channel, context);
final UnsignedShort remoteChannel = UnsignedShort.valueOf(channel);
final SessionTracker session = driver.sessions().getSessionFromRemoteChannel(remoteChannel);
if (session == null) {
throw new AssertionError(String.format("Received Disposition on channel [%s] that has no matching Session for that remote channel. ", remoteChannel));
}
session.handleDisposition(disposition);
}
use of org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedShort in project qpid-protonj2 by apache.
the class AttachExpectation method handleAttach.
// ----- Handle the performative and configure response is told to respond
@Override
public void handleAttach(int frameSize, Attach attach, ByteBuf payload, int channel, AMQPTestDriver context) {
super.handleAttach(frameSize, attach, payload, channel, context);
final UnsignedShort remoteChannel = UnsignedShort.valueOf(channel);
final SessionTracker session = driver.sessions().getSessionFromRemoteChannel(remoteChannel);
if (session == null) {
throw new AssertionError(String.format("Received Attach on channel [%s] that has no matching Session for that remote channel. ", remoteChannel));
}
final LinkTracker link = session.handleRemoteAttach(attach);
if (response != null) {
// to say otherwise by the test.
if (response.onChannel() == BeginInjectAction.CHANNEL_UNSET) {
response.onChannel(link.getSession().getLocalChannel());
}
// Populate the fields of the response with defaults if non set by the test script
if (response.getPerformative().getHandle() == null) {
response.withHandle(session.findFreeLocalHandle());
}
if (response.getPerformative().getName() == null) {
response.withName(attach.getName());
}
if (response.getPerformative().getRole() == null) {
response.withRole(Boolean.TRUE.equals(attach.getRole()) ? Role.SENDER : Role.RECEIVER);
}
if (response.getPerformative().getSenderSettleMode() == null) {
response.withSndSettleMode(SenderSettleMode.valueOf(attach.getSenderSettleMode()));
}
if (response.getPerformative().getReceiverSettleMode() == null) {
response.withRcvSettleMode(ReceiverSettleMode.valueOf(attach.getReceiverSettleMode()));
}
if (response.getPerformative().getSource() == null && !response.isNullSourceRequired()) {
response.withSource(attach.getSource());
if (attach.getSource() != null && Boolean.TRUE.equals(attach.getSource().getDynamic())) {
attach.getSource().setAddress(UUID.randomUUID().toString());
}
}
if (rejecting) {
if (Boolean.FALSE.equals(attach.getRole())) {
// Sender attach so response should have null target
response.withNullTarget();
} else {
// Receiver attach so response should have null source
response.withNullSource();
}
}
if (response.getPerformative().getTarget() == null && !response.isNullTargetRequired()) {
if (attach.getTarget() != null) {
if (attach.getTarget() instanceof Target) {
Target target = (Target) attach.getTarget();
response.withTarget(target);
if (target != null && Boolean.TRUE.equals(target.getDynamic())) {
target.setAddress(UUID.randomUUID().toString());
}
} else {
Coordinator coordinator = (Coordinator) attach.getTarget();
response.withTarget(coordinator);
}
}
}
if (response.getPerformative().getInitialDeliveryCount() == null) {
Role role = Role.valueOf(response.getPerformative().getRole());
if (role == Role.SENDER) {
response.withInitialDeliveryCount(0);
}
}
// Other fields are left not set for now unless test script configured
}
}
Aggregations