/** @test multiple ways how to initiate the advice collaboration */ void createCollaboration() { TheAdvised client1 ("topic1()"); TheAdvisor server2 ("topic2()"); int r1 (1 + (rand() % 1000)); int r2 (1 + (rand() % 1000)); server2.publish (r2); CHECK (client1.got(0)); TheAdvised client2 ("topic2()"); CHECK (client2.got(r2)); TheAdvisor server1; CHECK (client1.got(0)); server1.publish (r1); CHECK (client1.got(0)); CHECK (client2.got(r2)); server1.rebind ("topic1()"); CHECK (client1.got(r1)); CHECK (client2.got(r2)); }
int main(int argc, char **argv) { /* client1: nodeID B -> msg state server1: b nodeID msg N -> msg keys client2: state msg N -> keys */ if (argc < 2) { fprintf(stderr, "I need arguments. Read source for more info.\n"); return 1; } curve25519_init(); if (!strcmp(argv[1], "client1")) { return client1(argc, argv); } else if (!strcmp(argv[1], "server1")) { return server1(argc, argv); } else if (!strcmp(argv[1], "client2")) { return client2(argc, argv); } else { fprintf(stderr, "What's a %s?\n", argv[1]); return 1; } }
void tcp_client_1(cyg_addrword_t param) { diag_printf("Start TCP client 1 - test\n"); #if NLOOP > 0 client1(); #endif }
// Verifies that cached resources are evicted immediately after release when // the total dead resource size is more than double the dead resource capacity. static void TestClientRemoval(const ResourcePtr<Resource>& resource1, const ResourcePtr<Resource>& resource2) { const char data[6] = "abcde"; MockImageResourceClient client1(resource1); resource1->appendData(data, 4u); MockImageResourceClient client2(resource2); resource2->appendData(data, 4u); const unsigned minDeadCapacity = 0; const unsigned maxDeadCapacity = ((resource1->size() + resource2->size()) / 2) - 1; const unsigned totalCapacity = maxDeadCapacity; memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity); memoryCache()->add(resource1.get()); memoryCache()->add(resource2.get()); // Call prune. There is nothing to prune, but this will initialize // the prune timestamp, allowing future prunes to be deferred. memoryCache()->prune(); ASSERT_GT(resource1->decodedSize(), 0u); ASSERT_GT(resource2->decodedSize(), 0u); ASSERT_EQ(memoryCache()->deadSize(), 0u); ASSERT_EQ(memoryCache()->liveSize(), resource1->size() + resource2->size()); // Removing the client from resource1 should result in all resources // remaining in cache since the prune is deferred. client1.removeAsClient(); ASSERT_GT(resource1->decodedSize(), 0u); ASSERT_GT(resource2->decodedSize(), 0u); ASSERT_EQ(memoryCache()->deadSize(), resource1->size()); ASSERT_EQ(memoryCache()->liveSize(), resource2->size()); ASSERT_TRUE(memoryCache()->contains(resource1.get())); ASSERT_TRUE(memoryCache()->contains(resource2.get())); // Removing the client from resource2 should result in immediate // eviction of resource2 because we are over the prune deferral limit. client2.removeAsClient(); ASSERT_GT(resource1->decodedSize(), 0u); ASSERT_GT(resource2->decodedSize(), 0u); ASSERT_EQ(memoryCache()->deadSize(), resource1->size()); ASSERT_EQ(memoryCache()->liveSize(), 0u); ASSERT_TRUE(memoryCache()->contains(resource1.get())); ASSERT_FALSE(memoryCache()->contains(resource2.get())); }
int ServerApp::run (int argc, ACE_TCHAR* argv[]) { this->orb_ = CORBA::ORB_init (argc, argv); // Parse the command-line args for this application. // * Raises -1 if problems are encountered. // * Returns 1 if the usage statement was explicitly requested. // * Returns 0 otherwise. int result = this->parse_args (argc, argv); if (result != 0) { return result; } TheOrbShutdownTask::instance()->orb (this->orb_.in ()); if (synch_with_server_) { CORBA::Object_var manager_object = orb_->resolve_initial_references("ORBPolicyManager"); CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow(manager_object.in()); if (CORBA::is_nil (policy_manager.in ())) { ACE_ERROR ((LM_ERROR, " (%P|%t) Panic: nil PolicyManager\n")); throw TestException(); } CORBA::Any policy_value; policy_value <<= Messaging::SYNC_WITH_SERVER; CORBA::PolicyList policies(1); policies.length(1); policies[0] = orb_->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, policy_value); policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); } CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA"); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to resolve initial ref for 'RootPOA'.\n")); throw TestException(); } PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); if (CORBA::is_nil(root_poa.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to narrow obj ref to POA interface.\n")); throw TestException(); } PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // Create the child POA. CORBA::PolicyList policies(1); policies.length(1); policies[0] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); PortableServer::POA_var child_poa_1 = root_poa->create_POA("ChildPoa_1", poa_manager.in(), policies); if (CORBA::is_nil(child_poa_1.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to create the ChildPoa_1.\n")); throw TestException(); } PortableServer::POA_var child_poa_2 = root_poa->create_POA("ChildPoa_2", poa_manager.in(), policies); if (CORBA::is_nil(child_poa_2.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to create the ChildPoa_2.\n")); throw TestException(); } policies[0]->destroy (); // Create the thread pool servant dispatching strategy object, and // hold it in a (local) smart pointer variable. TAO_Intrusive_Ref_Count_Handle<TAO::CSD::TP_Strategy> csd_tp_strategy = new TAO::CSD::TP_Strategy(); // We need create multiple working threads otherwise it would deadlock // with the callback test. csd_tp_strategy->set_num_threads(2); // Tell the strategy to apply itself to the child poa. if (csd_tp_strategy->apply_to(child_poa_1.in()) == false) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to apply custom dispatching strategy to child poa 1.\n")); throw TestException(); } Foo_var foo1 = this->create_foo(child_poa_1.in(), "foo_applied_strategy"); Foo_var foo2 = this->create_foo(child_poa_2.in(), "foo_not_applied_strategy"); Callback_var callback1 = this->create_callback(child_poa_1.in(), "callback_applied_strategy"); Callback_var callback2 = this->create_callback(child_poa_2.in(), "callback_not_applied_strategy"); // Activate the POA Manager poa_manager->activate(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is ready. Running the ORB event loop.\n")); // Wait for the custom stretegy launch the dispatching threads. ACE_OS::sleep (2); ClientTask client1 (foo1.in (), callback1.in ()); if (client1.open() != 0) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to open the collocated client1.\n")); throw TestException(); } ClientTask client2 (foo2.in (), callback2.in ()); if (client2.open() != 0) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to open the collocated client2.\n")); throw TestException(); } // Run the ORB event loop. orb_->run(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp ORB has stopped running.\n")); ACE_DEBUG((LM_DEBUG, "(%P|%t) Wait for the OrbShutdownTask.\n")); TheOrbShutdownTask::instance()->wait (); ACE_DEBUG((LM_DEBUG, "(%P|%t) Wait for the collocated client task.\n")); client1.wait (); client2.wait (); ACE_DEBUG((LM_DEBUG, "(%P|%t) Stop the CSD strategy.\n")); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is destroying the Root POA.\n")); // Tear-down the root poa and orb_. root_poa->destroy(1, 1); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is destroying the ORB.\n")); orb_->destroy(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp has completed running successfully.\n")); return 0; }
int main() { int Choice = -1; Print((int)"*************************************client 1**************************************** \n"); Print("enter the test case choice \n"); /*Print("TestCase#1: Shows that signal only wakes up one thread,this thread goes on wait\n\n"); Print("TestCase#2: shows that broadcast wakes up all the threads,this thread goes on wait\n\n"); Print("TestCase#3: Tests the proper functioning of signal and wait \n\n"); Print("TestCase#4: Negative Test cases for Createlock and Createcv\n\n"); Print("TestCase#5: Negative Test cases for Destroylock and Destroycv\n\n"); Print("TestCase#6: Proper functioning of Create and Destroy Lock and condition\n\n"); Print("TestCase#7: Proper functioning of Acquire and Release \n\n"); Print("TestCase#8: Negative test cases for acquire and release \n\n"); Print("TestCase#9: Negative test cases for signal and wait \n\n"); Print("TestCase#10: Subsequent clients cannot acquire the lock until the previous clients release them \n\n"); Print("TestCase#11: To show that a lock or a CV cannot be destroyed by other client if this client is using it \n\n"); Print("TestCase#12: To show that a lock or a condition variable can only be destoyed if all clients using it call destroy \n\n"); */ Choice=Scan("%d"); switch (Choice) { case 1: client3(); break; case 2: client3(); break; case 3: Print("This test case checks the proper functioning of wait and signal RPC\n"); client1(); break; case 4: Print("The following are the negative test cases which will return error messages\n\n"); negativecase1(); break; case 5: Print("The following are the negative test cases which will return error messages\n\n\\"); negativecase2(); break; case 6: Print("Lock and CV are suceesfully created and deleted\n\n"); positivetestcase1(); break; case 7: Print("Locks are suceefully acquired and released\n\n"); positivetestcase2(); break; case 8: Print("We get error messages\n\n\n"); negativecase3(); break; case 9: Print("We get error messages\n\n\n"); negativecase4(); break; case 10: Print("Susequent clients can acquire the lock only when this client releases\n"); Lockacquiretest(); break; case 11: Print("To show that a lock or a CV cannot be destroyed by other client if this client is using it\n"); Lockdestroytest(); break; case 12: Print("To show that a lock or a condition variable can only be destoyed if all clients using it call destroy\n"); lockcvdestroytest(); break; } }
/** @test changing the provided advice, finally retracting it, * causing fallback on the default value. Any given advisor * can connect to the advice system with multiple bindings * consecutively. The connection has no identity beside this * binding, so another server (advisor) can step into an * existing connection and overwrite or retract the advice. * Unless retracted, advice remains in the system, * even after the advisor is gone. */ void overwriting_and_retracting() { TheAdvised client1 ("slot1"); TheAdvised client2 ("slot2"); CHECK (client1.got(0)); CHECK (client2.got(0)); int r1 (1 + (rand() % 1000)); int r2 (1 + (rand() % 1000)); { TheAdvisor server("slot1()"); CHECK (client1.got(0)); CHECK (client2.got(0)); server.publish (r1); CHECK (client1.got(r1)); CHECK (client2.got(0)); server.publish (r2); CHECK (client1.got(r2)); CHECK (client2.got(0)); server.rebind("slot2()"); CHECK (client1.got(0)); CHECK (client2.got(r2)); } CHECK (client1.got(0)); CHECK (client2.got(r2)); { TheAdvisor anotherServer("slot1"); CHECK (client1.got(0)); CHECK (client2.got(r2)); anotherServer.publish (r1); CHECK (client1.got(r1)); CHECK (client2.got(r2)); } CHECK (client1.got(r1)); CHECK (client2.got(r2)); { TheAdvisor yetAnotherServer("slot2"); CHECK (client1.got(r1)); CHECK (client2.got(r2)); yetAnotherServer.publish (r1); CHECK (client1.got(r1)); CHECK (client2.got(r1)); yetAnotherServer.rebind("slot1"); CHECK (client1.got(r1)); CHECK (client2.got(r2)); // ideally it should be 0, but actually we uncover the old provision // the decision was to err for a simple implementation /////////TICKET #623 yetAnotherServer.clear(); CHECK (client1.got(r1)); // should be 0, but again the existing provision is uncovered CHECK (client2.got(r2)); // should be 0 yetAnotherServer.rebind("slot2"); // no effect, because it doesn't provide advice anymore CHECK (client1.got(r1)); CHECK (client2.got(r2)); yetAnotherServer.publish (5); CHECK (client1.got(r1)); CHECK (client2.got(5)); } CHECK (client1.got(r1)); CHECK (client2.got(5)); client1.rebind("slot2"); CHECK (client1.got(5)); CHECK (client2.got(5)); client2.rebind("nonExistingSlot"); CHECK (client1.got(5)); CHECK (client2.got(0)); }
int main(int argc, char* argv[]) { try { // initialize logging - this reads the file log.xml from the current directory log_init(); // read the command line options cxxtools::Arg<std::string> ip(argc, argv, 'i'); // option -i <ip-addres> defines the address where to find the server cxxtools::Arg<bool> binary(argc, argv, 'b'); cxxtools::Arg<bool> json(argc, argv, 'j'); cxxtools::Arg<bool> jsonhttp(argc, argv, 'J'); cxxtools::Arg<std::size_t> timeout(argc, argv, 't', cxxtools::RemoteClient::WaitInfinite); cxxtools::Arg<unsigned short> port(argc, argv, 'p', binary ? 7003 : json ? 7004 : 7002); // we need a selector, which controls the network activity cxxtools::Selector selector; // Normally we would define just one rpc client for the protocol we use but // here we want to demonstrate, that it is just up to the client, which protocol // is used for the remote call. // One client can run just one request at a time. To run parallel requests // we need 2 clients. So we define 2 clients for each protocol. // define a xlmrpc client cxxtools::xmlrpc::HttpClient xmlrpcClient1(selector, ip, port, "/xmlrpc"); cxxtools::xmlrpc::HttpClient xmlrpcClient2(selector, ip, port, "/xmlrpc"); // and a binary rpc client cxxtools::bin::RpcClient binaryClient1(selector, ip, port); cxxtools::bin::RpcClient binaryClient2(selector, ip, port); // and a tcp json rpc client cxxtools::json::RpcClient jsonClient1(selector, ip, port); cxxtools::json::RpcClient jsonClient2(selector, ip, port); // and a http json rpc client cxxtools::json::HttpClient httpJsonClient1(selector, ip, port, "/jsonrpc"); cxxtools::json::HttpClient httpJsonClient2(selector, ip, port, "/jsonrpc"); // now se select the client depending on the command line flags cxxtools::RemoteClient& client1( binary ? static_cast<cxxtools::RemoteClient&>(binaryClient1) : json ? static_cast<cxxtools::RemoteClient&>(jsonClient1) : jsonhttp ? static_cast<cxxtools::RemoteClient&>(httpJsonClient1) : static_cast<cxxtools::RemoteClient&>(xmlrpcClient1)); cxxtools::RemoteClient& client2( binary ? static_cast<cxxtools::RemoteClient&>(binaryClient2) : json ? static_cast<cxxtools::RemoteClient&>(jsonClient2) : jsonhttp ? static_cast<cxxtools::RemoteClient&>(httpJsonClient2) : static_cast<cxxtools::RemoteClient&>(xmlrpcClient2)); // define remote procedure with dobule return value and two double parameters cxxtools::RemoteProcedure<double, double, double> add1(client1, "add"); cxxtools::RemoteProcedure<double, double, double> add2(client2, "add"); // initiate the execution of our method add1.begin(5, 6); add2.begin(1, 2); // Calling RemoteProcedure::end will run the underlying event loop until // the remote procedure is finished and return the result. // In case of a error, an exception is thrown. // Note that waiting for the end of one remote procedure will also start // and maybe finish the second remote procedure. double result1 = add1.end(timeout); std::cout << "result1=" << result1 << std::endl; // Here we run the loop again until the second procedure is finished. It // may well be, that the procedure is already finished and we get the // result immediately. double result2 = add2.end(timeout); std::cout << "result2=" << result2 << std::endl; } catch (const std::exception& e) { std::cerr << "error: " << e.what() << std::endl; } }
int main(void) { char buf[16]; /* Test simple data exchange, with explicit handshake. */ int u[2]; int rc = ipc_pair(u); errno_assert(rc == 0); int cr = go(client1(u[1])); errno_assert(cr >= 0); int s = tls_attach_server(u[0], "tests/cert.pem", "tests/key.pem", -1); errno_assert(s >= 0); rc = brecv(s, buf, 3, -1); errno_assert(rc == 0); assert(buf[0] == 'A' && buf[1] == 'B' && buf[2] == 'C'); rc = brecv(s, buf, 3, -1); errno_assert(rc == -1 && errno == EPIPE); rc = bsend(s, "DEF", 3, -1); errno_assert(rc == 0); rc = tls_done(s, -1); errno_assert(rc == 0); u[0] = tls_detach(s, -1); errno_assert(u[0] >= 0); rc = hclose(u[0]); errno_assert(rc == 0); rc = bundle_wait(cr, -1); errno_assert(rc == 0); rc = hclose(cr); errno_assert(rc == 0); /* Test simple data transfer, terminated by tls_detach(). Then send some data over undelying IPC connection. */ rc = ipc_pair(u); errno_assert(rc == 0); cr = go(client2(u[1])); errno_assert(cr >= 0); s = tls_attach_server(u[0], "tests/cert.pem", "tests/key.pem", -1); errno_assert(s >= 0); rc = brecv(s, buf, 3, -1); errno_assert(rc == 0); assert(buf[0] == 'A' && buf[1] == 'B' && buf[2] == 'C'); u[0] = tls_detach(s, -1); errno_assert(u[0] >= 0); rc = brecv(u[0], buf, 3, -1); errno_assert(rc == 0); assert(buf[0] == 'D' && buf[1] == 'E' && buf[2] == 'F'); rc = ipc_close(u[0], -1); errno_assert(rc == 0); rc = bundle_wait(cr, -1); errno_assert(rc == 0); rc = hclose(cr); errno_assert(rc == 0); /* Transfer large amount of data. */ rc = ipc_pair(u); errno_assert(rc == 0); cr = go(client3(u[1])); errno_assert(cr >= 0); s = tls_attach_server(u[0], "tests/cert.pem", "tests/key.pem", -1); errno_assert(s >= 0); uint8_t c = 0; int i; for(i = 0; i != 2777; ++i) { uint8_t b[257]; rc = brecv(s, b, sizeof(b), -1); errno_assert(rc == 0); int j; for(j = 0; j != sizeof(b); ++j) { assert(b[j] == c); c++; } } u[0] = tls_detach(s, -1); errno_assert(u[0] >= 0); rc = bundle_wait(cr, -1); errno_assert(rc == 0); rc = hclose(cr); errno_assert(rc == 0); rc = hclose(u[0]); errno_assert(rc == 0); return 0; }