Search in sources :

Example 6 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class ManagementTest method drainTemporaryMessageSource.

@Test
@SpecificationTest(section = "2.6.7", description = "The drain flag indicates how the sender SHOULD behave when insufficient messages" + " are available to consume the current link-credit. If set, the sender will" + " (after sending all available messages) advance the delivery-count as much as possible," + " consuming all link-credit, and send the flow state to the receiver.")
public void drainTemporaryMessageSource() throws Exception {
    assumeThat(getBrokerAdmin().isManagementSupported(), is(equalTo(true)));
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        Target target = new Target();
        target.setDynamicNodeProperties(Collections.singletonMap(Session_1_0.LIFETIME_POLICY, new DeleteOnClose()));
        target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
        target.setDynamic(true);
        target.setCapabilities(new Symbol[] { Symbol.valueOf("temporary-queue") });
        final Interaction interaction = transport.newInteraction();
        final Attach attachResponse = interaction.negotiateProtocol().consumeResponse().openHostname("$management").open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTarget(target).attach().consumeResponse().getLatestResponse(Attach.class);
        assertThat(attachResponse.getSource(), is(notNullValue()));
        assertThat(attachResponse.getTarget(), is(notNullValue()));
        String newTemporaryNodeAddress = ((Target) attachResponse.getTarget()).getAddress();
        assertThat(newTemporaryNodeAddress, is(notNullValue()));
        interaction.consumeResponse().getLatestResponse(Flow.class);
        final Attach receiverResponse = interaction.attachHandle(UnsignedInteger.ONE).attachRole(Role.RECEIVER).attachSourceAddress(newTemporaryNodeAddress).attachRcvSettleMode(ReceiverSettleMode.FIRST).attach().consumeResponse().getLatestResponse(Attach.class);
        assertThat(receiverResponse.getSource(), is(instanceOf(Source.class)));
        assertThat(((Source) receiverResponse.getSource()).getAddress(), is(equalTo(newTemporaryNodeAddress)));
        // 2.6.8  Synchronous Get
        // grant credit of 1
        interaction.flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
        // send drain to ensure the sender promptly advances the delivery-count until link-credit is consumed
        interaction.flowDrain(true).flow();
        Flow flow = interaction.consumeResponse().getLatestResponse(Flow.class);
        assertThat(flow.getLinkCredit(), is(equalTo(UnsignedInteger.ZERO)));
        assertThat(flow.getHandle(), is(equalTo(receiverResponse.getHandle())));
        interaction.doCloseConnection();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) DeleteOnClose(org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnClose) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 7 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class DeleteOnCloseTest method deleteOnCloseOnTarget.

@Test
@SpecificationTest(section = "3.5.10", description = "A node dynamically created with this lifetime policy will be deleted at the point that the link which caused its\n" + "creation ceases to exist.")
public void deleteOnCloseOnTarget() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        Target target = new Target();
        target.setDynamicNodeProperties(Collections.singletonMap(Session_1_0.LIFETIME_POLICY, new DeleteOnClose()));
        target.setDynamic(true);
        final Interaction interaction = transport.newInteraction();
        final Attach attachResponse = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTarget(target).attach().consumeResponse().getLatestResponse(Attach.class);
        assertThat(attachResponse.getTarget(), is(notNullValue()));
        final String newTempQueueAddress = ((Target) attachResponse.getTarget()).getAddress();
        assertThat(Utils.doesNodeExist(_brokerAddress, newTempQueueAddress), is(true));
        interaction.consumeResponse().getLatestResponse(Flow.class);
        interaction.detachClose(true).detach().consumeResponse().getLatestResponse(Detach.class);
        assertThat(Utils.doesNodeExist(_brokerAddress, newTempQueueAddress), is(false));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) DeleteOnClose(org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnClose) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 8 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class TransferTest method durableTransferWithRejectedOutcome.

@Test
@SpecificationTest(section = "3.2.1", description = "Durable messages MUST NOT be lost even if an intermediary is unexpectedly terminated and " + "restarted. A target which is not capable of fulfilling this guarantee MUST NOT accept messages " + "where the durable header is set to true: if the source allows the rejected outcome then the " + "message SHOULD be rejected with the precondition-failed error, otherwise the link MUST be " + "detached by the receiver with the same error.")
public void durableTransferWithRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        MessageEncoder messageEncoder = new MessageEncoder();
        final Header header = new Header();
        header.setDurable(true);
        messageEncoder.setHeader(header);
        messageEncoder.addData("foo");
        final Disposition receivedDisposition = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(messageEncoder.getPayload()).transferRcvSettleMode(ReceiverSettleMode.FIRST).transfer().consumeResponse().getLatestResponse(Disposition.class);
        assertThat(receivedDisposition.getSettled(), is(true));
        assertThat(receivedDisposition.getState(), is(instanceOf(Outcome.class)));
        if (getBrokerAdmin().supportsRestart()) {
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Accepted.ACCEPTED_SYMBOL));
        } else {
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Rejected.REJECTED_SYMBOL));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 9 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class TransferTest method durableTransferWithoutRejectedOutcome.

@Test
@SpecificationTest(section = "3.2.1", description = "Durable messages MUST NOT be lost even if an intermediary is unexpectedly terminated and " + "restarted. A target which is not capable of fulfilling this guarantee MUST NOT accept messages " + "where the durable header is set to true: if the source allows the rejected outcome then the " + "message SHOULD be rejected with the precondition-failed error, otherwise the link MUST be " + "detached by the receiver with the same error.")
public void durableTransferWithoutRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        MessageEncoder messageEncoder = new MessageEncoder();
        final Header header = new Header();
        header.setDurable(true);
        messageEncoder.setHeader(header);
        messageEncoder.addData("foo");
        final Response<?> response = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(messageEncoder.getPayload()).transferRcvSettleMode(ReceiverSettleMode.FIRST).transfer().consumeResponse().getLatestResponse();
        if (getBrokerAdmin().supportsRestart()) {
            assertThat(response, is(notNullValue()));
            assertThat(response.getBody(), is(instanceOf(Disposition.class)));
            final Disposition receivedDisposition = (Disposition) response.getBody();
            assertThat(receivedDisposition.getSettled(), is(true));
            assertThat(receivedDisposition.getState(), is(instanceOf(Outcome.class)));
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Accepted.ACCEPTED_SYMBOL));
        } else {
            assertThat(response, is(notNullValue()));
            assertThat(response.getBody(), is(instanceOf(Detach.class)));
            final Detach receivedDetach = (Detach) response.getBody();
            assertThat(receivedDetach.getError(), is(notNullValue()));
            assertThat(receivedDetach.getError().getCondition(), is(AmqpError.PRECONDITION_FAILED));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 10 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class BDBLinkStore method getLinkDefinitions.

private Collection<LinkDefinition<Source, Target>> getLinkDefinitions(final LinkStoreUpdater updater) {
    Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
    Collection<LinkDefinition<Source, Target>> links = new HashSet<>();
    ModelVersion currentVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION, BrokerModel.MODEL_MINOR_VERSION);
    ModelVersion storedVersion = getStoredVersion();
    if (currentVersion.lessThan(storedVersion)) {
        throw new StoreException(String.format("Cannot downgrade preference store from '%s' to '%s'", storedVersion, currentVersion));
    }
    try (Cursor cursor = linksDatabase.openCursor(null, null)) {
        final DatabaseEntry key = new DatabaseEntry();
        final DatabaseEntry value = new DatabaseEntry();
        LinkKeyEntryBinding keyEntryBinding = LinkKeyEntryBinding.getInstance();
        LinkValueEntryBinding linkValueEntryBinding = LinkValueEntryBinding.getInstance();
        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
            LinkKey linkKey = keyEntryBinding.entryToObject(key);
            LinkValue linkValue = linkValueEntryBinding.entryToObject(value);
            LinkDefinition<Source, Target> link = new LinkDefinitionImpl<>(linkKey.getRemoteContainerId(), linkKey.getLinkName(), linkKey.getRole(), linkValue.getSource(), linkValue.getTarget());
            links.add(link);
        }
    }
    if (storedVersion.lessThan(currentVersion)) {
        links = updater.update(storedVersion.toString(), links);
        final Transaction txn = getEnvironmentFacade().beginTransaction(null);
        try {
            linksDatabase = getEnvironmentFacade().clearDatabase(txn, LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
            for (LinkDefinition<Source, Target> link : links) {
                save(linksDatabase, txn, link);
            }
            updateVersion(txn, currentVersion.toString());
            txn.commit();
            linksDatabase.close();
        } catch (Exception e) {
            txn.abort();
            throw e;
        }
    }
    return links;
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) StoreException(org.apache.qpid.server.store.StoreException) DatabaseNotFoundException(com.sleepycat.je.DatabaseNotFoundException) StoreException(org.apache.qpid.server.store.StoreException) LinkDefinition(org.apache.qpid.server.protocol.v1_0.LinkDefinition) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) LinkDefinitionImpl(org.apache.qpid.server.protocol.v1_0.LinkDefinitionImpl) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) ModelVersion(org.apache.qpid.server.model.ModelVersion) HashSet(java.util.HashSet)

Aggregations

Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)14 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)11 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)11 Test (org.junit.Test)11 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)10 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)9 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)9 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)8 StoreException (org.apache.qpid.server.store.StoreException)8 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)7 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)6 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)6 PreparedStatement (java.sql.PreparedStatement)5 BaseTarget (org.apache.qpid.server.protocol.v1_0.type.BaseTarget)5 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)5 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)5 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)4 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)4 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)4