From e1564af7adc73529e6e9c768caf3eb46f00f8e28 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 9 Mar 2010 17:20:15 +0000 Subject: Remove tests/testagent sub-directory, build testagent in the tests directory. Resolves build-order issues, more consistent with the rest of the test builds. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@920991 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/tests/Makefile.am | 4 +- cpp/src/tests/testagent.cpp | 207 ++++++++++++++++++++++++++++++++++ cpp/src/tests/testagent.mk | 50 ++++++++ cpp/src/tests/testagent.xml | 64 +++++++++++ cpp/src/tests/testagent/Makefile.am | 53 --------- cpp/src/tests/testagent/schema.xml | 64 ----------- cpp/src/tests/testagent/testagent.cpp | 207 ---------------------------------- 7 files changed, 323 insertions(+), 326 deletions(-) create mode 100644 cpp/src/tests/testagent.cpp create mode 100644 cpp/src/tests/testagent.mk create mode 100644 cpp/src/tests/testagent.xml delete mode 100644 cpp/src/tests/testagent/Makefile.am delete mode 100644 cpp/src/tests/testagent/schema.xml delete mode 100644 cpp/src/tests/testagent/testagent.cpp (limited to 'cpp/src') diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index 64853345ba..7377edc3bb 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -17,8 +17,6 @@ # under the License. # -SUBDIRS = . testagent - AM_CXXFLAGS = $(WARNING_CFLAGS) -DBOOST_TEST_DYN_LINK INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src PUBLIC_INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include # Use public API only @@ -381,3 +379,5 @@ python_prep: --prefix=$(PYTHON_BLD_DIR) --install-lib=$(PYTHON_BLD_DIR) \ --install-scripts=$(PYTHON_BLD_DIR)/commands; \ else echo "WARNING: python client not built, missing $(PYTHON_SRC_DIR)"; fi + +include testagent.mk diff --git a/cpp/src/tests/testagent.cpp b/cpp/src/tests/testagent.cpp new file mode 100644 index 0000000000..61b47d83da --- /dev/null +++ b/cpp/src/tests/testagent.cpp @@ -0,0 +1,207 @@ +/* + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include "qmf/org/apache/qpid/agent/example/Parent.h" +#include "qmf/org/apache/qpid/agent/example/Child.h" +#include "qmf/org/apache/qpid/agent/example/ArgsParentCreate_child.h" +#include "qmf/org/apache/qpid/agent/example/EventChildCreated.h" +#include "qmf/org/apache/qpid/agent/example/Package.h" + +#include +#include +#include + +#include + +static bool running = true; + +using namespace std; +using qpid::management::ManagementAgent; +using qpid::management::ManagementObject; +using qpid::management::Manageable; +using qpid::management::Args; +using qpid::sys::Mutex; +namespace _qmf = qmf::org::apache::qpid::agent::example; + +class ChildClass; + +//============================================================== +// CoreClass is the operational class that corresponds to the +// "Parent" class in the management schema. +//============================================================== +class CoreClass : public Manageable +{ + string name; + ManagementAgent* agent; + _qmf::Parent* mgmtObject; + std::vector children; + Mutex vectorLock; + +public: + + CoreClass(ManagementAgent* agent, string _name); + ~CoreClass() { mgmtObject->resourceDestroy(); } + + ManagementObject* GetManagementObject(void) const + { return mgmtObject; } + + void doLoop(); + status_t ManagementMethod (uint32_t methodId, Args& args, string& text); +}; + +class ChildClass : public Manageable +{ + string name; + _qmf::Child* mgmtObject; + +public: + + ChildClass(ManagementAgent* agent, CoreClass* parent, string name); + ~ChildClass() { mgmtObject->resourceDestroy(); } + + ManagementObject* GetManagementObject(void) const + { return mgmtObject; } + + void doWork() + { + mgmtObject->inc_count(2); + } +}; + +CoreClass::CoreClass(ManagementAgent* _agent, string _name) : name(_name), agent(_agent) +{ + static uint64_t persistId = 0x111222333444555LL; + mgmtObject = new _qmf::Parent(agent, this, name); + + agent->addObject(mgmtObject, persistId++); + mgmtObject->set_state("IDLE"); +} + +void CoreClass::doLoop() +{ + // Periodically bump a counter to provide a changing statistical value + while (running) { + qpid::sys::sleep(1); + mgmtObject->inc_count(); + mgmtObject->set_state("IN_LOOP"); + + { + Mutex::ScopedLock _lock(vectorLock); + + for (std::vector::iterator iter = children.begin(); + iter != children.end(); + iter++) { + (*iter)->doWork(); + } + } + } +} + +Manageable::status_t CoreClass::ManagementMethod(uint32_t methodId, Args& args, string& /*text*/) +{ + Mutex::ScopedLock _lock(vectorLock); + + switch (methodId) { + case _qmf::Parent::METHOD_CREATE_CHILD: + _qmf::ArgsParentCreate_child& ioArgs = (_qmf::ArgsParentCreate_child&) args; + + ChildClass *child = new ChildClass(agent, this, ioArgs.i_name); + ioArgs.o_childRef = child->GetManagementObject()->getObjectId(); + + children.push_back(child); + + agent->raiseEvent(_qmf::EventChildCreated(ioArgs.i_name)); + + return STATUS_OK; + } + + return STATUS_NOT_IMPLEMENTED; +} + +ChildClass::ChildClass(ManagementAgent* agent, CoreClass* parent, string name) +{ + mgmtObject = new _qmf::Child(agent, this, parent, name); + + agent->addObject(mgmtObject); +} + + +//============================================================== +// Main program +//============================================================== + +ManagementAgent::Singleton* singleton; + +void shutdown(int) +{ + running = false; +} + +int main_int(int argc, char** argv) +{ + singleton = new ManagementAgent::Singleton(); + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + qpid::client::ConnectionSettings settings; + + settings.host = host; + settings.port = port; + + signal(SIGINT, shutdown); + + // Create the qmf management agent + ManagementAgent* agent = singleton->getInstance(); + + // Register the Qmf_example schema with the agent + _qmf::Package packageInit(agent); + + // Start the agent. It will attempt to make a connection to the + // management broker + agent->init(settings, 5, false, ".magentdata"); + + // Allocate some core objects + CoreClass core1(agent, "Example Core Object #1"); + CoreClass core2(agent, "Example Core Object #2"); + CoreClass core3(agent, "Example Core Object #3"); + + core1.doLoop(); + + // done, cleanup and exit + delete singleton; + + return 0; +} + +int main(int argc, char** argv) +{ + try { + return main_int(argc, argv); + } catch(std::exception& e) { + cerr << "Top Level Exception: " << e.what() << endl; + return 1; + } +} + diff --git a/cpp/src/tests/testagent.mk b/cpp/src/tests/testagent.mk new file mode 100644 index 0000000000..6d0d93bb82 --- /dev/null +++ b/cpp/src/tests/testagent.mk @@ -0,0 +1,50 @@ +# +# 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. +# + +# Build a simple qmf agent for test purposes. + +QMF_GEN=$(top_srcdir)/managementgen/qmf-gen + +TESTAGENT_GEN_SRC= \ + testagent_gen/qmf/org/apache/qpid/agent/example/Parent.h \ + testagent_gen/qmf/org/apache/qpid/agent/example/Child.h \ + testagent_gen/qmf/org/apache/qpid/agent/example/Parent.cpp \ + testagent_gen/qmf/org/apache/qpid/agent/example/Child.cpp \ + testagent_gen/qmf/org/apache/qpid/agent/example/ArgsParentCreate_child.h \ + testagent_gen/qmf/org/apache/qpid/agent/example/EventChildCreated.h \ + testagent_gen/qmf/org/apache/qpid/agent/example/EventChildDestroyed.h \ + testagent_gen/qmf/org/apache/qpid/agent/example/EventChildCreated.cpp \ + testagent_gen/qmf/org/apache/qpid/agent/example/EventChildDestroyed.cpp \ + testagent_gen/qmf/org/apache/qpid/agent/example/Package.h \ + testagent_gen/qmf/org/apache/qpid/agent/example/Package.cpp + +$(TESTAGENT_GEN_SRC): testagent_gen.timestamp + +testagent_gen.timestamp: testagent.xml + $(QMF_GEN) -o testagent_gen/qmf $(srcdir)/testagent.xml + touch testagent_gen.timestamp + +CLEANFILES+=$(TESTAGENT_GEN_SRC) testagent_gen.timestamp + +qpidtest_PROGRAMS+=testagent +testagent_CXXFLAGS=$(CXXFLAGS) -Itestagent_gen +testagent_SOURCES=testagent.cpp $(TESTAGENT_GEN_SRC) +testagent_LDADD=$(top_builddir)/src/libqmf.la + +EXTRA_DIST+=testagent.xml diff --git a/cpp/src/tests/testagent.xml b/cpp/src/tests/testagent.xml new file mode 100644 index 0000000000..8be21b7e68 --- /dev/null +++ b/cpp/src/tests/testagent.xml @@ -0,0 +1,64 @@ + + + + + + + + This class represents a parent object + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/src/tests/testagent/Makefile.am b/cpp/src/tests/testagent/Makefile.am deleted file mode 100644 index 160d8adb57..0000000000 --- a/cpp/src/tests/testagent/Makefile.am +++ /dev/null @@ -1,53 +0,0 @@ -# -# 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. -# - -# Build a simple qmf agent for test purposes. - -QMF_GEN=$(top_srcdir)/managementgen/qmf-gen -GEN_SRC= \ - gen/qmf/org/apache/qpid/agent/example/Parent.h \ - gen/qmf/org/apache/qpid/agent/example/Child.h \ - gen/qmf/org/apache/qpid/agent/example/Parent.cpp \ - gen/qmf/org/apache/qpid/agent/example/Child.cpp \ - gen/qmf/org/apache/qpid/agent/example/ArgsParentCreate_child.h \ - gen/qmf/org/apache/qpid/agent/example/EventChildCreated.h \ - gen/qmf/org/apache/qpid/agent/example/EventChildDestroyed.h \ - gen/qmf/org/apache/qpid/agent/example/EventChildCreated.cpp \ - gen/qmf/org/apache/qpid/agent/example/EventChildDestroyed.cpp \ - gen/qmf/org/apache/qpid/agent/example/Package.h \ - gen/qmf/org/apache/qpid/agent/example/Package.cpp - -$(GEN_SRC): gen.timestamp - -gen.timestamp: schema.xml - $(QMF_GEN) -o gen/qmf $(srcdir)/schema.xml - touch gen.timestamp - -CLEANFILES=$(GEN_SRC) gen.timestamp - -INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src -Igen - -qpidexecdir = $(libexecdir)/qpid -qpidtestdir = $(qpidexecdir)/tests - -qpidtest_PROGRAMS=testagent -testagent_SOURCES=testagent.cpp $(GEN_SRC) -testagent_LDADD=$(top_builddir)/src/libqmf.la - -EXTRA_DIST=schema.xml diff --git a/cpp/src/tests/testagent/schema.xml b/cpp/src/tests/testagent/schema.xml deleted file mode 100644 index 8be21b7e68..0000000000 --- a/cpp/src/tests/testagent/schema.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - This class represents a parent object - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/src/tests/testagent/testagent.cpp b/cpp/src/tests/testagent/testagent.cpp deleted file mode 100644 index 61b47d83da..0000000000 --- a/cpp/src/tests/testagent/testagent.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * - * 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. - * - */ - -#include -#include -#include -#include -#include -#include "qmf/org/apache/qpid/agent/example/Parent.h" -#include "qmf/org/apache/qpid/agent/example/Child.h" -#include "qmf/org/apache/qpid/agent/example/ArgsParentCreate_child.h" -#include "qmf/org/apache/qpid/agent/example/EventChildCreated.h" -#include "qmf/org/apache/qpid/agent/example/Package.h" - -#include -#include -#include - -#include - -static bool running = true; - -using namespace std; -using qpid::management::ManagementAgent; -using qpid::management::ManagementObject; -using qpid::management::Manageable; -using qpid::management::Args; -using qpid::sys::Mutex; -namespace _qmf = qmf::org::apache::qpid::agent::example; - -class ChildClass; - -//============================================================== -// CoreClass is the operational class that corresponds to the -// "Parent" class in the management schema. -//============================================================== -class CoreClass : public Manageable -{ - string name; - ManagementAgent* agent; - _qmf::Parent* mgmtObject; - std::vector children; - Mutex vectorLock; - -public: - - CoreClass(ManagementAgent* agent, string _name); - ~CoreClass() { mgmtObject->resourceDestroy(); } - - ManagementObject* GetManagementObject(void) const - { return mgmtObject; } - - void doLoop(); - status_t ManagementMethod (uint32_t methodId, Args& args, string& text); -}; - -class ChildClass : public Manageable -{ - string name; - _qmf::Child* mgmtObject; - -public: - - ChildClass(ManagementAgent* agent, CoreClass* parent, string name); - ~ChildClass() { mgmtObject->resourceDestroy(); } - - ManagementObject* GetManagementObject(void) const - { return mgmtObject; } - - void doWork() - { - mgmtObject->inc_count(2); - } -}; - -CoreClass::CoreClass(ManagementAgent* _agent, string _name) : name(_name), agent(_agent) -{ - static uint64_t persistId = 0x111222333444555LL; - mgmtObject = new _qmf::Parent(agent, this, name); - - agent->addObject(mgmtObject, persistId++); - mgmtObject->set_state("IDLE"); -} - -void CoreClass::doLoop() -{ - // Periodically bump a counter to provide a changing statistical value - while (running) { - qpid::sys::sleep(1); - mgmtObject->inc_count(); - mgmtObject->set_state("IN_LOOP"); - - { - Mutex::ScopedLock _lock(vectorLock); - - for (std::vector::iterator iter = children.begin(); - iter != children.end(); - iter++) { - (*iter)->doWork(); - } - } - } -} - -Manageable::status_t CoreClass::ManagementMethod(uint32_t methodId, Args& args, string& /*text*/) -{ - Mutex::ScopedLock _lock(vectorLock); - - switch (methodId) { - case _qmf::Parent::METHOD_CREATE_CHILD: - _qmf::ArgsParentCreate_child& ioArgs = (_qmf::ArgsParentCreate_child&) args; - - ChildClass *child = new ChildClass(agent, this, ioArgs.i_name); - ioArgs.o_childRef = child->GetManagementObject()->getObjectId(); - - children.push_back(child); - - agent->raiseEvent(_qmf::EventChildCreated(ioArgs.i_name)); - - return STATUS_OK; - } - - return STATUS_NOT_IMPLEMENTED; -} - -ChildClass::ChildClass(ManagementAgent* agent, CoreClass* parent, string name) -{ - mgmtObject = new _qmf::Child(agent, this, parent, name); - - agent->addObject(mgmtObject); -} - - -//============================================================== -// Main program -//============================================================== - -ManagementAgent::Singleton* singleton; - -void shutdown(int) -{ - running = false; -} - -int main_int(int argc, char** argv) -{ - singleton = new ManagementAgent::Singleton(); - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - qpid::client::ConnectionSettings settings; - - settings.host = host; - settings.port = port; - - signal(SIGINT, shutdown); - - // Create the qmf management agent - ManagementAgent* agent = singleton->getInstance(); - - // Register the Qmf_example schema with the agent - _qmf::Package packageInit(agent); - - // Start the agent. It will attempt to make a connection to the - // management broker - agent->init(settings, 5, false, ".magentdata"); - - // Allocate some core objects - CoreClass core1(agent, "Example Core Object #1"); - CoreClass core2(agent, "Example Core Object #2"); - CoreClass core3(agent, "Example Core Object #3"); - - core1.doLoop(); - - // done, cleanup and exit - delete singleton; - - return 0; -} - -int main(int argc, char** argv) -{ - try { - return main_int(argc, argv); - } catch(std::exception& e) { - cerr << "Top Level Exception: " << e.what() << endl; - return 1; - } -} - -- cgit v1.2.1