You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by fa...@apache.org on 2013/04/08 17:19:09 UTC

svn commit: r1465662 [24/26] - in /qpid/trunk/qpid/tools/src/java: ./ bin/ bin/qpid-web/ bin/qpid-web/authentication/ bin/qpid-web/web/ bin/qpid-web/web/itablet/ bin/qpid-web/web/itablet/css/ bin/qpid-web/web/itablet/images/ bin/qpid-web/web/itablet/im...

Added: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,558 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.AgentExternal;
+import org.apache.qpid.qmf2.agent.MethodCallParams;
+import org.apache.qpid.qmf2.agent.MethodCallWorkItem;
+import org.apache.qpid.qmf2.agent.ResubscribeParams;
+import org.apache.qpid.qmf2.agent.ResubscribeRequestWorkItem;
+import org.apache.qpid.qmf2.agent.SubscribeRequestWorkItem;
+import org.apache.qpid.qmf2.agent.SubscribableAgent;
+import org.apache.qpid.qmf2.agent.Subscription;
+import org.apache.qpid.qmf2.agent.SubscriptionParams;
+import org.apache.qpid.qmf2.agent.UnsubscribeRequestWorkItem;
+import org.apache.qpid.qmf2.agent.QueryWorkItem;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.QmfType;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.SchemaProperty;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * Class used to test the AgentExternal.
+ * This class provides a demo of all of the features available on the AgentExternal model including Subscriptions.
+ * It provides essentially the same behaviour as the AgentTest class though requires a lot more code.
+ *
+ * The AgentExternal class and this demo are largely provided for completeness (although they do behave correctly)
+ * as the author isn't convinced that there's a good reason for using AgentExternal rather than Agent.
+ *
+ * @author Fraser Adams
+ */
+public final class AgentExternalTest implements QmfEventListener, SubscribableAgent
+{
+    /** 
+     * This TimerTask causes the Agent to Reap any objects marked as deleted when it gets scheduled
+     */
+    private final class Reaper extends TimerTask
+    {
+        public void run()
+        {
+            // Reap any QmfAgentData Objects that have been marked as Deleted
+            // Use the iterator approach rather than foreach as we may want to call iterator.remove() to zap an entry
+            Iterator<QmfAgentData> i = _objectIndex.values().iterator();
+            while (i.hasNext())
+            {
+                QmfAgentData object = i.next();
+                if (object.isDeleted())
+                {
+System.out.println("****** Removing deleted Object *******");
+                    i.remove();
+                }
+            }
+        }
+    }
+
+    private AgentExternal _agent;
+    private QmfAgentData _control;
+    private SchemaObjectClass _exceptionSchema;
+    private SchemaObjectClass _controlSchema;
+    private SchemaObjectClass _childSchema;
+    private SchemaEventClass _eventSchema;
+
+    /**
+     * objectIndex is the global index of QmfAgentData objects registered with this Agent
+     */
+    private Map<ObjectId, QmfAgentData> _objectIndex = new ConcurrentHashMap<ObjectId, QmfAgentData>();
+
+    /**
+     * This Map is used to look up Subscriptions by SubscriptionId
+     */
+    private Map<String, Subscription> _subscriptions = new ConcurrentHashMap<String, Subscription>();
+
+    private Timer _timer;
+
+    public AgentExternalTest(String url)
+    {
+        try
+        {
+            System.out.println("** Starting AgentExternalTest a test of basic AgentExternal class functions **");
+                
+            Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+            _agent = new AgentExternal(this);
+            _agent.setVendor("profitron.com");
+            _agent.setProduct("gizmo");
+            _agent.setValue("attr1", 2000);
+
+            System.out.println("Agent name: " + _agent.getName());
+
+            // Schedule a Reap every 10 seconds sending the first one immediately
+            _timer = new Timer(true);
+            _timer.schedule(new Reaper(), 0, 10000);
+
+            setupSchema();
+            populateData();
+
+            _agent.setConnection(connection);
+
+            for (int i = 0; i < 100; i++)
+            {
+                _control.setValue("offset", i);
+                //control.update(); // Send data indication to the Subscriber on the next Subscription interval
+                _control.publish(); // Send data indication to the Subscriber immediately
+                try
+                {
+                    Thread.sleep(1000);
+                }
+                catch (InterruptedException ie)
+                {
+                }
+            }
+
+            _control.destroy();
+
+
+            // A getObjects call seems necessary to enable automatic reconnection when broker restarts
+            // I've got no idea why this is the case though!!!
+            //List<QmfConsoleData> connections = console.getObjects("broker");
+        }
+        catch (QmfException qmfe)
+        {
+            System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentExternalTest failed");
+        }
+    }
+
+    public void onEvent(WorkItem wi)
+    {
+        System.out.println("WorkItem type: " + wi.getType());
+
+        if (wi.getType() == METHOD_CALL)
+        {
+            _control.incValue("methodCount", 1);
+
+            MethodCallWorkItem item = (MethodCallWorkItem)wi;
+            MethodCallParams methodCallParams = item.getMethodCallParams();
+            String methodName = methodCallParams.getName();
+            ObjectId objectId = methodCallParams.getObjectId();
+            String userId = methodCallParams.getUserId();
+            QmfData inArgs = methodCallParams.getArgs();
+            ObjectId controlAddress = _control.getObjectId();
+
+            System.out.println("Method Call User ID = " + userId);
+
+            try
+            {
+                if (objectId == null)
+                {
+                    // Method invoked directly on Agent
+                    if (methodName.equals("toString"))
+                    {
+                        QmfData outArgs = new QmfData();
+                        outArgs.setValue("string", _agent.toString());
+                        _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+                    }
+                }
+                else if (objectId.equals(controlAddress))
+                {
+                    if (methodName.equals("stop"))
+                    {
+                        System.out.println("Invoked stop method");
+                        String message = inArgs.getStringValue("message");
+                        System.out.println("Stopping: message = " + message);
+                        _agent.methodResponse(methodName, item.getHandle(), null, null);
+                        _agent.destroy();
+                        System.exit(1);
+                    }
+                    else if (methodName.equals("echo"))
+                    {
+                        System.out.println("Invoked echo method");
+                        _agent.methodResponse(methodName, item.getHandle(), inArgs, null);
+                    }
+                    else if (methodName.equals("event"))
+                    {
+                        System.out.println("Invoked event method");
+                        QmfEvent event = new QmfEvent(_eventSchema);
+                        event.setSeverity((int)inArgs.getLongValue("severity"));
+                        event.setValue("text", inArgs.getStringValue("text"));
+                        _agent.raiseEvent(event);
+                        _agent.methodResponse(methodName, item.getHandle(), null, null);
+                    }
+                    else if (methodName.equals("fail"))
+                    {
+                        System.out.println("Invoked fail method");
+                        QmfData error = new QmfData();
+                        if (inArgs.getBooleanValue("useString"))
+                        {
+                            error.setValue("error_text", inArgs.getStringValue("stringVal"));
+                        }
+                        else
+                        {
+                            error.setValue("whatHappened", "It Failed");
+                            error.setValue("howBad", 75);
+                            error.setValue("details", inArgs.getValue("details"));
+                        }
+                        _agent.methodResponse(methodName, item.getHandle(), null, error);
+                    }
+                    else if (methodName.equals("create_child"))
+                    {
+                        System.out.println("Invoked create_child method");
+                        String childName = inArgs.getStringValue("name");
+                        System.out.println("childName = " + childName);
+                        QmfAgentData child = new QmfAgentData(_childSchema);
+                        child.setValue("name", childName);
+                        addObject(child);
+                        QmfData outArgs = new QmfData();
+                        outArgs.setRefValue("childAddr", child.getObjectId(), "reference"); // Set suptype just to test
+                        _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+                    }
+                }
+            }
+            catch (QmfException qmfe)
+            {
+                System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentExternalTest failed");
+                QmfData error = new QmfData();
+                error.setValue("error_text", qmfe.getMessage());
+                _agent.methodResponse(methodName, item.getHandle(), null, error);
+            }
+        }
+
+        if (wi.getType() == QUERY)
+        {
+            QueryWorkItem item = (QueryWorkItem)wi;
+            QmfQuery query = item.getQmfQuery();
+
+            System.out.println("Query User ID = " + item.getUserId());
+
+            if (query.getObjectId() != null)
+            {
+                // Look up a QmfAgentData object by the ObjectId obtained from the query
+                ObjectId objectId = query.getObjectId();
+                QmfAgentData object = _objectIndex.get(objectId);
+                if (object != null && !object.isDeleted())
+                {
+                    _agent.queryResponse(item.getHandle(), object);
+                }
+                _agent.queryComplete(item.getHandle(), 0);
+            }
+            else
+            {
+                // Look up QmfAgentData objects by the SchemaClassId obtained from the query
+                // This is implemented by a linear search and allows searches with only the className specified.
+                // Linear searches clearly don't scale brilliantly, but the number of QmfAgentData objects managed
+                // by an Agent is generally fairly small, so it should be OK. Note that this is the same approach
+                // taken by the C++ broker ManagementAgent, so if it's a problem here........
+                for (QmfAgentData object : _objectIndex.values())
+                {
+                    if (!object.isDeleted() && query.evaluate(object))
+                    {
+                        _agent.queryResponse(item.getHandle(), object);
+                    }
+                }
+                _agent.queryComplete(item.getHandle(), 0);
+            }
+        }
+
+        if (wi.getType() == SUBSCRIBE_REQUEST)
+        {
+            SubscribeRequestWorkItem item = (SubscribeRequestWorkItem)wi;
+            SubscriptionParams params = item.getSubscriptionParams();
+            Handle handle = item.getHandle();
+
+            System.out.println("Subscribe Request User ID = " + params.getUserId());
+
+            try
+            {
+                Subscription subscription = new Subscription(this, params);
+                _subscriptions.put(subscription.getSubscriptionId(), subscription);
+                _timer.schedule(subscription, 0, params.getPublishInterval());
+
+                if (subscription == null)
+                {
+System.out.println("Requested Subscription has already expired or been cancelled");
+                    QmfData error = new QmfData();
+                    error.setValue("error_text", "Requested Subscription has already expired or been cancelled");
+                    _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), null, 0, 0, error);
+                }
+                else
+                {
+                    _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), subscription.getSubscriptionId(), 
+                                               subscription.getDuration(), subscription.getInterval(), null);
+                }
+            }
+            catch (QmfException qmfe)
+            {
+                _agent.raiseException(handle, "Subscribe Request failed, invalid Query: " + qmfe.getMessage());
+            }
+        }
+
+        if (wi.getType() == RESUBSCRIBE_REQUEST)
+        {
+            ResubscribeRequestWorkItem item = (ResubscribeRequestWorkItem)wi;
+            ResubscribeParams params = item.getResubscribeParams();
+            Handle handle = item.getHandle();
+
+            System.out.println("Resubscribe Request User ID = " + params.getUserId());
+
+            String subscriptionId = params.getSubscriptionId();
+            Subscription subscription = _subscriptions.get(subscriptionId);
+            if (subscription != null)
+            {
+                subscription.refresh(params);
+                _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), subscription.getSubscriptionId(), 
+                                           subscription.getDuration(), subscription.getInterval(), null);
+            }
+            else
+            {
+System.out.println("Requested Subscription has already expired or been cancelled");
+                QmfData error = new QmfData();
+                error.setValue("error_text", "Requested Subscription has already expired or been cancelled");
+                _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), null, 0, 0, error);
+            }
+        }
+
+        if (wi.getType() == UNSUBSCRIBE_REQUEST)
+        {
+            UnsubscribeRequestWorkItem item = (UnsubscribeRequestWorkItem)wi;
+            String subscriptionId = item.getSubscriptionId();
+System.out.println("Received cancellation request for " + subscriptionId);
+            Subscription subscription = _subscriptions.get(subscriptionId);
+            if (subscription != null)
+            {
+                subscription.cancel();
+            }
+        }
+
+    }
+
+    public void setupSchema() throws QmfException
+    {
+        System.out.println("*** AgentExternalTest initialising the various Schema classes ***");
+                
+        // Create and register schema for this agent.
+        String packageName = "com.profitron.gizmo";
+
+        // Declare a schema for a structured exception that can be used in failed method invocations.
+        _exceptionSchema = new SchemaObjectClass(packageName, "exception");
+        _exceptionSchema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+        _exceptionSchema.addProperty(new SchemaProperty("howBad", QmfType.TYPE_INT));
+        _exceptionSchema.addProperty(new SchemaProperty("details", QmfType.TYPE_MAP));
+
+        // Declare a control object to test methods against.
+        _controlSchema = new SchemaObjectClass(packageName, "control");
+        _controlSchema.addProperty(new SchemaProperty("state", QmfType.TYPE_STRING));
+        _controlSchema.addProperty(new SchemaProperty("methodCount", QmfType.TYPE_INT));
+        _controlSchema.addProperty(new SchemaProperty("offset", QmfType.TYPE_INT));
+        _controlSchema.setIdNames("state");
+
+        SchemaMethod stopMethod = new SchemaMethod("stop", "Stop Agent");
+        stopMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:IN}"));
+        _controlSchema.addMethod(stopMethod);
+
+        SchemaMethod echoMethod = new SchemaMethod("echo", "Echo Arguments");
+        echoMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:INOUT}"));
+        _controlSchema.addMethod(echoMethod);
+
+        SchemaMethod eventMethod = new SchemaMethod("event", "Raise an Event");
+        eventMethod.addArgument(new SchemaProperty("text", QmfType.TYPE_STRING, "{dir:IN}"));
+        eventMethod.addArgument(new SchemaProperty("severity", QmfType.TYPE_INT, "{dir:IN}"));
+        _controlSchema.addMethod(eventMethod);
+
+        SchemaMethod failMethod = new SchemaMethod("fail", "Expected to Fail");
+        failMethod.addArgument(new SchemaProperty("useString", QmfType.TYPE_BOOL, "{dir:IN}"));
+        failMethod.addArgument(new SchemaProperty("stringVal", QmfType.TYPE_STRING, "{dir:IN}"));
+        failMethod.addArgument(new SchemaProperty("details", QmfType.TYPE_MAP, "{dir:IN}"));
+        _controlSchema.addMethod(failMethod);
+
+        SchemaMethod createMethod = new SchemaMethod("create_child", "Create Child Object");
+        createMethod.addArgument(new SchemaProperty("name", QmfType.TYPE_STRING, "{dir:IN}"));
+        createMethod.addArgument(new SchemaProperty("childAddr", QmfType.TYPE_MAP, "{dir:OUT}"));
+        _controlSchema.addMethod(createMethod);
+
+        // Declare the child class
+        _childSchema = new SchemaObjectClass(packageName, "child");
+        _childSchema.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+        _childSchema.setIdNames("name");
+    
+        // Declare the event class
+        _eventSchema = new SchemaEventClass(packageName, "event");
+        _eventSchema.addProperty(new SchemaProperty("text", QmfType.TYPE_STRING));
+
+        System.out.println("AgentExternalTest Schema classes initialised OK");
+
+        _agent.registerObjectClass(_exceptionSchema);
+        _agent.registerObjectClass(_controlSchema);
+        _agent.registerObjectClass(_childSchema);
+        _agent.registerEventClass(_eventSchema);
+
+        System.out.println("AgentExternalTest Schema classes registered OK");
+    }
+
+    public void populateData() throws QmfException
+    {
+        System.out.println("*** AgentExternalTest creating a control object ***");
+
+        _control = new QmfAgentData(_controlSchema);
+        _control.setValue("state", "OPERATIONAL");
+        _control.setValue("methodCount", 0);
+
+        addObject(_control);
+        System.out.println("AgentExternalTest Schema control object added OK");
+    }
+
+    public void addObject(QmfAgentData object) throws QmfException
+    {
+        ObjectId addr = _agent.allocObjectId(UUID.randomUUID().toString());
+        object.setObjectId(addr);
+        _objectIndex.put(addr, object);
+
+        // Does the new object match any Subscriptions? If so add a reference to the matching Subscription and publish.
+        for (Subscription subscription : _subscriptions.values())
+        {
+            QmfQuery query = subscription.getQuery();
+            if (query.getObjectId() != null)
+            {
+                if (query.getObjectId().equals(addr))
+                {
+                    object.addSubscription(subscription.getSubscriptionId(), subscription);
+                    object.publish();
+                }
+            }
+            else if (query.evaluate(object))
+            {
+                object.addSubscription(subscription.getSubscriptionId(), subscription);
+                object.publish();
+            }
+        }
+    }
+
+
+
+    //                               methods implementing SubscriberProxy interface
+    // ********************************************************************************************************
+
+    /**
+     * Send a list of updated subscribed data to the Console.
+     *
+     * @param handle the console reply handle
+     * @param results a list of subscribed data in Map encoded form
+     */
+    public void sendSubscriptionIndicate(Handle handle, List<Map> results)
+    {
+        _agent.sendSubscriptionIndicate(handle, results);
+    }
+
+    /**
+     * This method evaluates a QmfQuery over the Agent's data on behalf of a Subscription
+     *
+     * @param query the QmfQuery that the Subscription wants to be evaluated over the Agent's data
+     * @return a List of QmfAgentData objects that match the specified QmfQuery
+     */
+    public List<QmfAgentData> evaluateQuery(QmfQuery query)
+    {
+        List<QmfAgentData> results = new ArrayList<QmfAgentData>(_objectIndex.size());
+        if (query.getTarget() == QmfQueryTarget.OBJECT)
+        {
+            if (query.getObjectId() != null)
+            {
+                // Look up a QmfAgentData object by the ObjectId obtained from the query
+                ObjectId objectId = query.getObjectId();
+                QmfAgentData object = _objectIndex.get(objectId);
+                if (object != null && !object.isDeleted())
+                {
+                    results.add(object);
+                }
+            }
+            else
+            {
+                // Look up QmfAgentData objects evaluating the query
+                for (QmfAgentData object : _objectIndex.values())
+                {
+                    if (!object.isDeleted() && query.evaluate(object))
+                    {
+                        results.add(object);
+                    }
+                }
+            }
+        }
+        return results;
+    }
+
+    /**
+     * This method is called by the Subscription to tell the SubscriberProxy that the Subscription has been cancelled.
+     *
+     * @param subscription the Subscription that has been cancelled and is requesting removal.
+     */
+    public void removeSubscription(Subscription subscription)
+    {
+        _subscriptions.remove(subscription.getSubscriptionId());
+    }
+
+
+    public static void main(String[] args)
+    {
+        //System.out.println("Setting log level to FATAL");
+        System.setProperty("amqj.logging.level", "FATAL");
+
+        String url = (args.length == 1) ? args[0] : "localhost";
+        AgentExternalTest test1 = new AgentExternalTest(url);
+
+        BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+        try
+        { // Blocks here until return is pressed
+            System.out.println("Hit Return to exit");
+            String s = commandLine.readLine();
+            System.exit(0);
+        }
+        catch (IOException e)
+        {
+            System.out.println ("ConnectionAudit main(): IOException: " + e.getMessage());
+        }
+
+        System.out.println("*** Ending AgentExternalTest ***");
+    }
+}

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,224 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.MethodResponseWorkItem;
+import org.apache.qpid.qmf2.console.ObjectUpdateWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.console.SubscribeIndication;
+import org.apache.qpid.qmf2.console.SubscribeParams;
+import org.apache.qpid.qmf2.console.SubscribeResponseWorkItem;
+import org.apache.qpid.qmf2.console.SubscriptionIndicationWorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * This class is the Console part of AgentTest which together provide a test of subscription behaviour
+ *
+ * N.B. AgentTest needs to be running for this test to behave as expected.
+ *
+ * @author Fraser Adams
+ */
+public final class AgentSubscriptionTestConsole implements QmfEventListener
+{
+    private Console _console;
+    private Agent _gizmo;
+
+    public AgentSubscriptionTestConsole(String url)
+    {
+        try
+        {
+            System.out.println("** Starting AgentSubscriptionTestConsole used to test subscription behaviour **");
+                
+            Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+            _console = new Console(this);
+            _console.addConnection(connection);
+
+            // Wait until the gizmo Agent has been discovered
+            _gizmo = _console.findAgent("gizmo");
+            if (_gizmo == null)
+            {
+                System.out.println("gizmo Agent not found, you probably need to run AgentTest1");
+                System.exit(1);
+            }
+
+            System.out.println("Creating Query for objects whose state property has a value that starts with 'OP'");
+
+            SubscribeParams params;
+            QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, "['re_match', 'state', ['quote', '^OP']]");
+
+            // Create a subscription, response returned synchronously
+            params = _console.createSubscription(_gizmo, query, "consoleHandle1", "{publishInterval:5}");
+            System.out.println("duration = " + params.getLifetime());
+            System.out.println("interval = " + params.getPublishInterval());
+            System.out.println("subscriptionId = " + params.getSubscriptionId());
+            System.out.println("consoleHandle = " + params.getConsoleHandle());
+
+            // Sleep a while, getting query result as they become available
+            try
+            {
+                Thread.sleep(20000);
+            }
+            catch (InterruptedException ie)
+            {
+            }
+
+            // Refresh the subscription getting results asynchronously, just for variety
+            System.out.println("Calling refreshSubscription on " + params.getSubscriptionId());
+            _console.refreshSubscription(params.getSubscriptionId(), "{replyHandle:ignored}");
+
+
+            // Sleep a bit more
+            try
+            {
+                Thread.sleep(350000);
+            }
+            catch (InterruptedException ie)
+            {
+            }
+
+        }
+        catch (QmfException qmfe)
+        {
+            System.err.println("QmfException " + qmfe.getMessage() + ": AgentSubscriptionTestConsole failed");
+            System.exit(1);
+        }
+    }
+
+    public void onEvent(WorkItem wi)
+    {
+        System.out.println("WorkItem type: " + wi.getType());
+
+        if (wi.getType() == AGENT_HEARTBEAT)
+        {
+            AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem)wi;
+            Agent agent = item.getAgent();
+            System.out.println(agent.getName());
+        }
+
+        if (wi.getType() == EVENT_RECEIVED)
+        {
+            EventReceivedWorkItem item = (EventReceivedWorkItem)wi;
+            Agent agent = item.getAgent();
+            QmfEvent event = item.getEvent();
+
+            String className = event.getSchemaClassId().getClassName();
+            System.out.println("Event: " + className);
+//event.listValues();    
+        }
+
+        if (wi.getType() == METHOD_RESPONSE)
+        {
+            MethodResponseWorkItem item = (MethodResponseWorkItem)wi;
+            MethodResult result = item.getMethodResult();
+            String correlationId = item.getHandle().getCorrelationId();
+            System.out.println("correlationId = " + correlationId);
+            System.out.println(result.getStringValue("message"));
+        }
+
+        if (wi.getType() == OBJECT_UPDATE)
+        {
+            ObjectUpdateWorkItem item = (ObjectUpdateWorkItem)wi;
+            QmfConsoleData object = item.getQmfConsoleData();
+            ObjectId objectId = object.getObjectId();
+            String correlationId = item.getHandle().getCorrelationId();
+            System.out.println("correlationId = " + correlationId);
+            System.out.println("objectId = " + objectId);
+            System.out.println("MethodCount = " + object.getLongValue("methodCount"));
+        }
+
+        if (wi.getType() == SUBSCRIBE_RESPONSE)
+        {
+            SubscribeResponseWorkItem item = (SubscribeResponseWorkItem)wi;
+            SubscribeParams params = item.getSubscribeParams();
+            System.out.println("duration = " + params.getLifetime());
+            System.out.println("interval = " + params.getPublishInterval());
+            System.out.println("subscriptionId = " + params.getSubscriptionId());
+            System.out.println("consoleHandle = " + params.getConsoleHandle());
+            String correlationId = item.getHandle().getCorrelationId();
+            System.out.println("correlationId = " + correlationId);
+        }
+
+        if (wi.getType() == SUBSCRIPTION_INDICATION)
+        {
+            SubscriptionIndicationWorkItem item = (SubscriptionIndicationWorkItem)wi;
+            SubscribeIndication indication = item.getSubscribeIndication();
+            String correlationId = indication.getConsoleHandle();
+            System.out.println("correlationId = " + correlationId);
+
+            List<QmfConsoleData> objects = indication.getData();
+            for (QmfConsoleData object : objects)
+            {
+                if (object.isDeleted())
+                {
+                    System.out.println("object has been deleted");
+                }
+                System.out.println("offset = " + object.getValue("offset"));
+            }
+        }
+    }
+
+    public static void main(String[] args)
+    {
+        //System.out.println ("Setting log level to FATAL");
+        System.setProperty("amqj.logging.level", "FATAL");
+
+        String url = (args.length == 1) ? args[0] : "localhost";
+        AgentSubscriptionTestConsole test = new AgentSubscriptionTestConsole(url);
+
+        BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+        try
+        { // Blocks here until return is pressed
+            System.out.println("Hit Return to exit");
+            String s = commandLine.readLine();
+            System.exit(0);
+        }
+        catch (IOException e)
+        {
+            System.out.println ("AgentSubscriptionTestConsole main(): IOException: " + e.getMessage());
+        }
+
+        System.out.println("*** Ending AgentSubscriptionTestConsole ***");
+    }
+}

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,298 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.Agent;
+import org.apache.qpid.qmf2.agent.MethodCallParams;
+import org.apache.qpid.qmf2.agent.MethodCallWorkItem;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfType;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.SchemaProperty;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * A class used to test the Agent API functionality.
+ *
+ * @author Fraser Adams
+ */
+public final class AgentTest implements QmfEventListener
+{
+    private Agent _agent;
+    private QmfAgentData _control;
+    private SchemaObjectClass _exceptionSchema;
+    private SchemaObjectClass _controlSchema;
+    private SchemaObjectClass _childSchema;
+    private SchemaEventClass _eventSchema;
+
+    public AgentTest(String url)
+    {
+        try
+        {
+            System.out.println("** Starting AgentTest a test of basic Agent class functions **");
+                
+            Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+            _agent = new Agent(this);
+            _agent.setVendor("profitron.com");
+            _agent.setProduct("gizmo");
+            _agent.setValue("attr1", 2000);
+
+            System.out.println("Agent name: " + _agent.getName());
+
+            setupSchema();
+            populateData();
+
+            _agent.setConnection(connection);
+
+            for (int i = 0; i < 100; i++)
+            {
+                _control.setValue("offset", i);
+                //control.update(); // Send data indication to the Subscriber on the next Subscription interval
+                _control.publish(); // Send data indication to the Subscriber immediately
+                try
+                {
+                    Thread.sleep(1000);
+                }
+                catch (InterruptedException ie)
+                {
+                }
+            }
+
+            _control.destroy();
+
+        }
+        catch (QmfException qmfe)
+        {
+            System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentTest failed");
+        }
+    }
+
+    public void onEvent(WorkItem wi)
+    {
+        System.out.println("WorkItem type: " + wi.getType());
+        _control.incValue("methodCount", 1);
+
+        if (wi.getType() == METHOD_CALL)
+        {
+            MethodCallWorkItem item = (MethodCallWorkItem)wi;
+            MethodCallParams methodCallParams = item.getMethodCallParams();
+            String methodName = methodCallParams.getName();
+            ObjectId objectId = methodCallParams.getObjectId();
+            String userId = methodCallParams.getUserId();
+            userId = userId.equals("") ? "anonymous" : userId;
+            QmfData inArgs = methodCallParams.getArgs();
+            ObjectId controlAddress = _control.getObjectId();
+
+            System.out.println("Method Call User ID = " + userId);
+
+            try
+            {
+                if (objectId == null)
+                {
+                    // Method invoked directly on Agent
+                    if (methodName.equals("toString"))
+                    {
+                        QmfData outArgs = new QmfData();
+                        outArgs.setValue("string", _agent.toString());
+                        _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+                    }
+                }
+                else if (objectId.equals(controlAddress))
+                {
+                    if (methodName.equals("stop"))
+                    {
+                        System.out.println("Invoked stop method");
+                        String message = inArgs.getStringValue("message");
+                        System.out.println("Stopping: message = " + message);
+                        _agent.methodResponse(methodName, item.getHandle(), null, null);
+                        _agent.destroy();
+                        System.exit(1);
+                    }
+                    else if (methodName.equals("echo"))
+                    {
+                        System.out.println("Invoked echo method");
+                        _agent.methodResponse(methodName, item.getHandle(), inArgs, null);
+                    }
+                    else if (methodName.equals("event"))
+                    {
+                        System.out.println("Invoked event method");
+                        QmfEvent event = new QmfEvent(_eventSchema);
+                        event.setSeverity((int)inArgs.getLongValue("severity"));
+                        event.setValue("text", inArgs.getStringValue("text"));
+                        _agent.raiseEvent(event);
+                        _agent.methodResponse(methodName, item.getHandle(), null, null);
+                    }
+                    else if (methodName.equals("fail"))
+                    {
+                        System.out.println("Invoked fail method");
+                        QmfData error = new QmfData();
+                        if (inArgs.getBooleanValue("useString"))
+                        {
+                            error.setValue("error_text", inArgs.getStringValue("stringVal"));
+                        }
+                        else
+                        {
+                            error.setValue("whatHappened", "It Failed");
+                            error.setValue("howBad", 75);
+                            error.setValue("details", inArgs.getValue("details"));
+                        }
+                        _agent.methodResponse(methodName, item.getHandle(), null, error);
+                    }
+                    else if (methodName.equals("create_child"))
+                    {
+                        System.out.println("Invoked create_child method");
+                        String childName = inArgs.getStringValue("name");
+                        System.out.println("childName = " + childName);
+                        QmfAgentData child = new QmfAgentData(_childSchema);
+                        child.setValue("name", childName);
+                        _agent.addObject(child);
+                        QmfData outArgs = new QmfData();
+                        outArgs.setRefValue("childAddr", child.getObjectId(), "reference"); // Set subtype just to test
+                        _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+                    }
+                }
+            }
+            catch (QmfException qmfe)
+            {
+                System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentTest failed");
+                QmfData error = new QmfData();
+                error.setValue("error_text", qmfe.getMessage());
+                _agent.methodResponse(methodName, item.getHandle(), null, error);
+            }
+        }
+    }
+
+    public void setupSchema() throws QmfException
+    {
+        System.out.println("*** AgentTest initialising the various Schema classes ***");
+                
+        // Create and register schema for this agent.
+        String packageName = "com.profitron.gizmo";
+
+        // Declare a schema for a structured exception that can be used in failed method invocations.
+        _exceptionSchema = new SchemaObjectClass(packageName, "exception");
+        _exceptionSchema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+        _exceptionSchema.addProperty(new SchemaProperty("howBad", QmfType.TYPE_INT));
+        _exceptionSchema.addProperty(new SchemaProperty("details", QmfType.TYPE_MAP));
+
+        // Declare a control object to test methods against.
+        _controlSchema = new SchemaObjectClass(packageName, "control");
+        _controlSchema.addProperty(new SchemaProperty("state", QmfType.TYPE_STRING));
+        _controlSchema.addProperty(new SchemaProperty("methodCount", QmfType.TYPE_INT));
+        _controlSchema.addProperty(new SchemaProperty("offset", QmfType.TYPE_INT));
+        _controlSchema.setIdNames("state");
+
+        SchemaMethod stopMethod = new SchemaMethod("stop", "Stop Agent");
+        stopMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:IN}"));
+        _controlSchema.addMethod(stopMethod);
+
+        SchemaMethod echoMethod = new SchemaMethod("echo", "Echo Arguments");
+        echoMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:INOUT}"));
+        _controlSchema.addMethod(echoMethod);
+
+        SchemaMethod eventMethod = new SchemaMethod("event", "Raise an Event");
+        eventMethod.addArgument(new SchemaProperty("text", QmfType.TYPE_STRING, "{dir:IN}"));
+        eventMethod.addArgument(new SchemaProperty("severity", QmfType.TYPE_INT, "{dir:IN}"));
+        _controlSchema.addMethod(eventMethod);
+
+        SchemaMethod failMethod = new SchemaMethod("fail", "Expected to Fail");
+        failMethod.addArgument(new SchemaProperty("useString", QmfType.TYPE_BOOL, "{dir:IN}"));
+        failMethod.addArgument(new SchemaProperty("stringVal", QmfType.TYPE_STRING, "{dir:IN}"));
+        failMethod.addArgument(new SchemaProperty("details", QmfType.TYPE_MAP, "{dir:IN}"));
+        _controlSchema.addMethod(failMethod);
+
+        SchemaMethod createMethod = new SchemaMethod("create_child", "Create Child Object");
+        createMethod.addArgument(new SchemaProperty("name", QmfType.TYPE_STRING, "{dir:IN}"));
+        createMethod.addArgument(new SchemaProperty("childAddr", QmfType.TYPE_MAP, "{dir:OUT}"));
+        _controlSchema.addMethod(createMethod);
+
+        // Declare the child class
+        _childSchema = new SchemaObjectClass(packageName, "child");
+        _childSchema.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+        _childSchema.setIdNames("name");
+    
+        // Declare the event class
+        _eventSchema = new SchemaEventClass(packageName, "event");
+        _eventSchema.addProperty(new SchemaProperty("text", QmfType.TYPE_STRING));
+
+        System.out.println("AgentTest Schema classes initialised OK");
+
+        _agent.registerObjectClass(_exceptionSchema);
+        _agent.registerObjectClass(_controlSchema);
+        _agent.registerObjectClass(_childSchema);
+        _agent.registerEventClass(_eventSchema);
+
+        System.out.println("AgentTest Schema classes registered OK");
+    }
+
+    public void populateData() throws QmfException
+    {
+        System.out.println("*** AgentTest creating a control object ***");
+
+        _control = new QmfAgentData(_controlSchema);
+        _control.setValue("state", "OPERATIONAL");
+        _control.setValue("methodCount", 0);
+        _agent.addObject(_control);
+        System.out.println("AgentTest Schema control object added OK");
+    }
+
+
+    public static void main(String[] args)
+    {
+        //System.out.println("Setting log level to FATAL");
+        System.setProperty("amqj.logging.level", "FATAL");
+
+        String url = (args.length == 1) ? args[0] : "localhost";
+        AgentTest test1 = new AgentTest(url);
+
+        BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+        try
+        { // Blocks here until return is pressed
+            System.out.println("Hit Return to exit");
+            String s = commandLine.readLine();
+            System.exit(0);
+        }
+        catch (IOException e)
+        {
+            System.out.println ("ConnectionAudit main(): IOException: " + e.getMessage());
+        }
+
+        System.out.println("*** Ending AgentTest ***");
+    }
+}

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,308 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.MethodResponseWorkItem;
+import org.apache.qpid.qmf2.console.ObjectUpdateWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * This class is the Console part of AgentTest which together provide a test of a number of core Console and
+ * Agent behaviours such as Schema creation, registration and lookup, Object lookup, method invocation on Objects
+ * Object refreshing (updating state of local proxy objects from the real Agent).
+ *
+ * N.B. AgentTest needs to be running for this test to behave as expected.
+ *
+ * @author Fraser Adams
+ */
+public final class AgentTestConsole implements QmfEventListener
+{
+    private Console _console;
+    private Agent _gizmo;
+
+    public AgentTestConsole(String url)
+    {
+        try
+        {
+            System.out.println("*** Starting AgentTestConsole used to test basic Console and Agent behaviour ***");
+                
+            Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+            _console = new Console(this);
+            _console.addConnection(connection);
+
+            // Wait until the gizmo Agent has been discovered
+            synchronized(this)
+            {
+                while (_gizmo == null)
+                {
+                    long startTime = System.currentTimeMillis();
+                    try
+                    {
+                        wait(10*1000);
+                    }
+                    catch (InterruptedException ie)
+                    {
+                        continue;
+                    }
+                    // Measure elapsed time to test against spurious wakeups and ensure we really have timed out
+                    long elapsedTime = (System.currentTimeMillis() - startTime)/1000;
+                    if (_gizmo == null && elapsedTime >= 10)
+                    {
+                        System.out.println("gizmo Agent not found, you probably need to run AgentTest");
+                        System.exit(1);
+                    }
+                }
+            }
+
+            System.out.println("Testing lookup of control objects by name");
+            List<QmfConsoleData> controls = _console.getObjects("com.profitron.gizmo", "control");
+            if (controls.size() > 0)
+            {
+                System.out.println("control object found");
+                QmfConsoleData control = controls.get(0);
+                //control.listValues();
+
+                ObjectId oid = control.getObjectId();
+                //System.out.println("Agent Name = " + oid.getAgentName());
+                //System.out.println("Agent Epoch = " + oid.getAgentEpoch());
+                //System.out.println("Object Name = " + oid.getObjectName());
+
+                System.out.println("Testing lookup of object by ObjectId");
+                controls = _console.getObjects(oid);
+
+                if (controls.size() == 0)
+                {
+                    System.out.println("No objects returned from ObjectId lookup: AgentTestConsole failed");
+                    System.exit(1);
+                }
+
+                System.out.println("MethodCount = " + control.getLongValue("methodCount"));
+                QmfData inArgs;
+                QmfData outArgs;
+                MethodResult results;
+
+/*
+                System.out.println("Testing invokeMethod(toString, args) - method called directly on Agent");
+                results = _gizmo.invokeMethod("toString", null);
+                System.out.println("gizmo.toString() = " + results.getArguments().getStringValue("string"));
+*/
+
+                // ********** Invoke create_child nethod **********
+                System.out.println("Testing invokeMethod(create_child, args)");
+                inArgs = new QmfData();
+                inArgs.setValue("name", "child 1");
+
+                results = control.invokeMethod("create_child", inArgs);
+                if (!results.succeeded())
+                {
+                    System.out.println("create_child returned an exception object");
+                    System.exit(1);
+                }
+
+                if (!results.hasValue("childAddr"))
+                {
+                    System.out.println("create_child returned an unexpected value");
+                    System.exit(1);
+                }
+
+                ObjectId childId = results.getRefValue("childAddr");        
+                System.out.println("childId = " + childId);
+                System.out.println("childAddr subtype = " + results.getSubtype("childAddr"));
+                QmfConsoleData child1 = _console.getObjects(childId).get(0);
+                System.out.println("child1 name = " + child1.getStringValue("name"));
+
+
+                // Update and display state of control object
+                control.refresh();
+                System.out.println("MethodCount = " + control.getLongValue("methodCount"));
+
+
+                // ********** Invoke event nethod **********
+                System.out.println("Testing invokeMethod(event, args) ");
+                inArgs = new QmfData();
+                inArgs.setValue("text", "Attention Will Robinson!! Aliens have just invaded");
+                inArgs.setValue("severity", 0);
+                control.invokeMethod("event", inArgs);
+
+
+                // Update and display state of control object
+                control.refresh();
+                System.out.println("MethodCount = " + control.getLongValue("methodCount"));
+
+
+                // ********** Invoke fail nethod **********
+                System.out.println("Testing invokeMethod(fail, args) ");
+                QmfData details = new QmfData();
+                details.setValue("detail1", "something bad");
+                details.setValue("detail2", "something even badder");
+                inArgs = new QmfData();
+                inArgs.setValue("details", details.mapEncode());
+                results = control.invokeMethod("fail", inArgs);
+                System.out.println("whatHappened: " + results.getStringValue("whatHappened"));
+                System.out.println("howBad: " + results.getLongValue("howBad"));
+
+                // Update and display state of control object
+                control.refresh();
+                System.out.println("MethodCount = " + control.getLongValue("methodCount"));
+
+
+                // ********** Invoke echo nethod asynchronously **********
+                System.out.println("Testing asynchronous call of invokeMethod(echo, args) ");
+                inArgs = new QmfData();
+                inArgs.setValue("message", "This message should be echoed by the Agent");
+                control.invokeMethod("echo", inArgs, "echoMethodCorrelationId");
+
+
+                // Asynchronous update and display state of control object. The state here should be the same as
+                // the last time it was called as this is an asynchronous refresh. The ObjectUpdateWorkItem in
+                // the event handler contains the new state
+                control.refresh("echoMethodCorrelationId");
+                System.out.println("MethodCount = " + control.getLongValue("methodCount") + " (should be same as last value)");
+
+
+
+                // ********** Invoke stop nethod, this will stop the Agent **********
+                System.out.println("Testing invokeMethod(stop, args) ");
+                inArgs = new QmfData();
+                inArgs.setValue("message", "Ladies and gentlemen Elvis has just left the building");
+                control.invokeMethod("stop", inArgs);
+
+
+            }
+            else
+            {
+                System.out.println("No control objects returned: AgentTestConsole failed");
+                System.exit(1);
+            }
+        }
+        catch (QmfException qmfe)
+        {
+            System.err.println("QmfException " + qmfe.getMessage() + ": AgentTestConsole failed");
+            System.exit(1);
+        }
+    }
+
+    public void onEvent(WorkItem wi)
+    {
+        System.out.println("WorkItem type: " + wi.getType());
+
+        if (wi.getType() == AGENT_ADDED)
+        {
+            AgentAddedWorkItem item = (AgentAddedWorkItem)wi;
+            Agent agent = item.getAgent();
+
+            // If this is the gizmo Agent we notify the main thread so processing can continue.
+            if (agent.getProduct().equals("gizmo"))
+            {
+                synchronized(this)
+                {
+                    _gizmo = agent;
+                    notify();
+                }
+            }
+        }
+
+        if (wi.getType() == AGENT_HEARTBEAT)
+        {
+            AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem)wi;
+            Agent agent = item.getAgent();
+            System.out.println(agent.getName());
+        }
+
+        if (wi.getType() == EVENT_RECEIVED)
+        {
+            EventReceivedWorkItem item = (EventReceivedWorkItem)wi;
+            Agent agent = item.getAgent();
+            QmfEvent event = item.getEvent();
+
+            String className = event.getSchemaClassId().getClassName();
+            System.out.println("Event: " + className);
+//event.listValues();    
+        }
+
+        if (wi.getType() == METHOD_RESPONSE)
+        {
+            MethodResponseWorkItem item = (MethodResponseWorkItem)wi;
+            MethodResult result = item.getMethodResult();
+            String correlationId = item.getHandle().getCorrelationId();
+            System.out.println("correlationId = " + correlationId);
+            System.out.println(result.getStringValue("message"));
+        }
+
+        if (wi.getType() == OBJECT_UPDATE)
+        {
+            ObjectUpdateWorkItem item = (ObjectUpdateWorkItem)wi;
+            QmfConsoleData object = item.getQmfConsoleData();
+            ObjectId objectId = object.getObjectId();
+            String correlationId = item.getHandle().getCorrelationId();
+            System.out.println("correlationId = " + correlationId);
+            System.out.println("objectId = " + objectId);
+            System.out.println("MethodCount = " + object.getLongValue("methodCount"));
+        }
+
+    }
+
+    public static void main(String[] args)
+    {
+        //System.out.println ("Setting log level to FATAL");
+        System.setProperty("amqj.logging.level", "FATAL");
+
+        String url = (args.length == 1) ? args[0] : "localhost";
+        AgentTestConsole test = new AgentTestConsole(url);
+
+        BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+        try
+        { // Blocks here until return is pressed
+            System.out.println("Hit Return to exit");
+            String s = commandLine.readLine();
+            System.exit(0);
+        }
+        catch (IOException e)
+        {
+            System.out.println ("AgentTestConsole main(): IOException: " + e.getMessage());
+        }
+
+        System.out.println("*** Ending AgentTestConsole ***");
+    }
+}

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,174 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.Agent;
+import org.apache.qpid.qmf2.agent.MethodCallParams;
+import org.apache.qpid.qmf2.agent.MethodCallWorkItem;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfType;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.SchemaProperty;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * A class used to test the Agent API functionality. This Agent specifies an explicit queue name and a larger than
+ * default queue size so that it can receive large payloads on its methods.
+ *
+ * @author Fraser Adams
+ */
+public final class BigPayloadAgentTest implements QmfEventListener
+{
+    private Agent _agent;
+    private QmfAgentData _control;
+    private SchemaObjectClass _controlSchema;
+
+    public BigPayloadAgentTest(String url)
+    {
+        try
+        {
+            System.out.println("** Starting BigPayloadAgentTest a test of basic Agent class functions **");
+                
+            Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+            _agent = new Agent(this);
+            _agent.setVendor("test.com");
+            _agent.setProduct("big-payload-agent");
+
+            System.out.println("Agent name: " + _agent.getName());
+
+            setupSchema();
+            populateData();
+            _agent.setConnection(connection, " ; {link: {name:'big-payload-agent', x-declare: {arguments: {'qpid.policy_type': ring, 'qpid.max_size': 500000000}}}}");
+
+        }
+        catch (QmfException qmfe)
+        {
+            System.err.println("QmfException " + qmfe.getMessage() + " caught: BigPayloadAgentTest failed");
+        }
+    }
+
+    public void onEvent(WorkItem wi)
+    {
+        System.out.println("WorkItem type: " + wi.getType());
+
+        if (wi.getType() == METHOD_CALL)
+        {
+            MethodCallWorkItem item = (MethodCallWorkItem)wi;
+            MethodCallParams methodCallParams = item.getMethodCallParams();
+            String methodName = methodCallParams.getName();
+            ObjectId objectId = methodCallParams.getObjectId();
+
+            QmfData inArgs = methodCallParams.getArgs();
+            ObjectId controlAddress = _control.getObjectId();
+
+            if (objectId.equals(controlAddress))
+            {
+                if (methodName.equals("processPayload"))
+                {
+                    System.out.println("Invoked processPayload method");
+
+                    byte[] parameter = inArgs.getValue("parameter");
+                    System.out.println("payload size = " + parameter.length);
+
+                    QmfData outArgs = new QmfData();
+                    outArgs.setValue("return", parameter);
+                    _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+                }
+            }
+        }
+    }
+
+    public void setupSchema() throws QmfException
+    {
+        System.out.println("*** BigPayloadAgentTest initialising the various Schema classes ***");
+                
+        // Create and register schema for this agent.
+        String packageName = "com.test.bigagent";
+
+        // Declare a control object to test methods against.
+        _controlSchema = new SchemaObjectClass(packageName, "control");
+        _controlSchema.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+        _controlSchema.setIdNames("name");
+
+        SchemaMethod createMethod = new SchemaMethod("processPayload", "Process a large payload");
+        createMethod.addArgument(new SchemaProperty("parameter", QmfType.TYPE_STRING, "{dir:IN}"));
+        createMethod.addArgument(new SchemaProperty("return", QmfType.TYPE_STRING, "{dir:OUT}"));
+        _controlSchema.addMethod(createMethod);
+ 
+        System.out.println("BigPayloadAgentTest Schema classes initialised OK");
+
+        _agent.registerObjectClass(_controlSchema);
+
+        System.out.println("BigPayloadAgentTest Schema classes registered OK");
+    }
+
+    public void populateData() throws QmfException
+    {
+        System.out.println("*** BigPayloadAgentTest creating a control object ***");
+
+        _control = new QmfAgentData(_controlSchema);
+        _control.setValue("name", "controller");
+        _agent.addObject(_control);
+        System.out.println("BigPayloadAgentTest Schema control object added OK");
+    }
+
+
+    public static void main(String[] args)
+    {
+        //System.out.println("Setting log level to FATAL");
+        System.setProperty("amqj.logging.level", "FATAL");
+
+        String url = (args.length == 1) ? args[0] : "localhost";
+        BigPayloadAgentTest test1 = new BigPayloadAgentTest(url);
+
+        BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+        try
+        { // Blocks here until return is pressed
+            System.out.println("Hit Return to exit");
+            String s = commandLine.readLine();
+            System.exit(0);
+        }
+        catch (IOException e)
+        {
+            System.out.println ("ConnectionAudit main(): IOException: " + e.getMessage());
+        }
+
+        System.out.println("*** Ending BigPayloadAgentTest ***");
+    }
+}

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,155 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.MethodResponseWorkItem;
+import org.apache.qpid.qmf2.console.ObjectUpdateWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * This class is the Console part of AgentTest which together provide a test of a number of core Console and
+ * Agent behaviours such as Schema creation, registration and lookup, Object lookup, method invocation on Objects
+ * Object refreshing (updating state of local proxy objects from the real Agent).
+ *
+ * N.B. AgentTest needs to be running for this test to behave as expected.
+ *
+ * @author Fraser Adams
+ */
+public final class BigPayloadAgentTestConsole implements QmfEventListener
+{
+    private Console _console;
+    private Agent _agent;
+
+    public BigPayloadAgentTestConsole(String url)
+    {
+        try
+        {
+            System.out.println("*** Starting BigPayloadAgentTestConsole used to test basic Console and Agent behaviour ***");
+                
+            Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+            _console = new Console(this);
+            _console.addConnection(connection, " ; {link: {name:'big-payload-console', x-declare: {arguments: {'qpid.policy_type': ring, 'qpid.max_size': 500000000}}}}");
+
+            // Wait until the broker Agent has been discovered
+            _agent = _console.findAgent("big-payload-agent");
+            if (_agent == null)
+            {
+                System.out.println("Big Payload Agent not found");
+                System.exit(1);
+            }
+
+            List<QmfConsoleData> controls = _console.getObjects("com.test.bigagent", "control");
+            if (controls.size() > 0)
+            {
+                QmfConsoleData control = controls.get(0);
+
+                // ********** Invoke processPayload nethod **********
+                System.out.println("Testing invokeMethod(processPayload, args)");
+                QmfData inArgs = new QmfData();
+                inArgs.setValue("parameter", new byte[150000000]);
+
+                MethodResult results = control.invokeMethod("processPayload", inArgs);
+                if (!results.succeeded())
+                {
+                    System.out.println("processPayload returned an exception object");
+                    System.exit(1);
+                }
+
+                if (!results.hasValue("return"))
+                {
+                    System.out.println("processPayload returned an unexpected value");
+                    System.exit(1);
+                }
+
+                byte[] returnVal = results.getValue("return");        
+                System.out.println("returnVal size = " + returnVal.length);
+            }
+            else
+            {
+                System.out.println("No control objects returned: BigPayloadAgentTestConsole failed");
+                System.exit(1);
+            }
+        }
+        catch (QmfException qmfe)
+        {
+            System.err.println("QmfException " + qmfe.getMessage() + ": BigPayloadAgentTestConsole failed");
+            System.exit(1);
+        }
+    }
+
+    public void onEvent(WorkItem wi)
+    {
+        //System.out.println("WorkItem type: " + wi.getType());
+
+        if (wi.getType() == AGENT_HEARTBEAT)
+        {
+            AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem)wi;
+            Agent agent = item.getAgent();
+            System.out.println(agent.getName());
+        }
+    }
+
+    public static void main(String[] args)
+    {
+        //System.out.println ("Setting log level to FATAL");
+        System.setProperty("amqj.logging.level", "FATAL");
+
+        String url = (args.length == 1) ? args[0] : "localhost";
+        BigPayloadAgentTestConsole test = new BigPayloadAgentTestConsole(url);
+
+        BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+        try
+        { // Blocks here until return is pressed
+            System.out.println("Hit Return to exit");
+            String s = commandLine.readLine();
+            System.exit(0);
+        }
+        catch (IOException e)
+        {
+            System.out.println ("BigPayloadAgentTestConsole main(): IOException: " + e.getMessage());
+        }
+
+        System.out.println("*** Ending BigPayloadAgentTestConsole ***");
+    }
+}

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org