Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROTON-1224: Upgrade BouncyCastle #75

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ include_directories(${ProtonCpp_INCLUDE_DIRS})
link_libraries(${ProtonCpp_LIBRARIES})
add_definitions(${CXX_WARNING_FLAGS})

# Single-threaded examples.
# Single-threaded examples that work on C++03
foreach(example
broker
helloworld
helloworld_direct
simple_recv
simple_send
scheduled_send_03
direct_recv
direct_send
client
Expand All @@ -45,6 +46,14 @@ foreach(example
add_executable(${example} ${example}.cpp)
endforeach()

# Single-threaded examples that require C++11
if(HAS_CPP11)
foreach(example
scheduled_send)
add_executable(${example} ${example}.cpp)
endforeach()
endif()

# Python test runner
set(env_py ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/proton-c/env.py)

Expand Down
16 changes: 16 additions & 0 deletions examples/cpp/README.dox
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,19 @@ A multithreaded broker, that will work on any multi-threaded container. See @ref
__Requires C++11__

*/

/** @example schedule_send.cpp

Shows how to use proton::container::schedule to schedule a timed callback.
This version uses std::function and so requires C++11 or better. For a C++03 compatible
approach see @ref schedule_send_03.cpp.

*/

/** @example schedule_send_03.cpp

Shows how to use proton::container::schedule to schedule a timed callback in a
C++03 compatible way. See @ref schedule_send.cpp for a more convenient approach
using std::function if you have C++11.

*/
22 changes: 14 additions & 8 deletions examples/cpp/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,20 @@ def test_ssl_client_cert(self):
expect_found = (out.find(expect) >= 0)
self.assertEqual(expect_found, True)

def test_scheduled_send_03(self):
# Output should be a bunch of "send" lines but can't guarantee exactly how many.
out = self.proc(["scheduled_send_03", "-a", self.addr+"scheduled_send", "-t", "0.1", "-i", "0.001"]).wait_exit().split()
self.assertGreater(len(out), 0);
self.assertEqual(["send"]*len(out), out)

def test_scheduled_send(self):
try:
out = self.proc(["scheduled_send", "-a", self.addr+"scheduled_send", "-t", "0.1", "-i", "0.001"]).wait_exit().split()
self.assertGreater(len(out), 0);
self.assertEqual(["send"]*len(out), out)
except ProcError: # File not found, not a C++11 build.
pass


class EngineTestCase(BrokerTestCase):
"""Run selected clients to test a connction_engine broker."""
Expand Down Expand Up @@ -377,14 +391,6 @@ def test_request_response(self):
self.assertEqual(CLIENT_EXPECT,
self.proc(["client", "-a", self.addr]).wait_exit())

def test_flow_control(self):
return
want="""success: Example 1: simple credit
success: Example 2: basic drain
success: Example 3: drain without credit
success: Exmaple 4: high/low watermark
"""
self.assertEqual(want, self.proc(["flow_control", pick_addr(), "-quiet"]).wait_exit())

class MtBrokerTest(EngineTestCase):
broker_exe = "mt_broker"
Expand Down
12 changes: 10 additions & 2 deletions examples/cpp/mt/epoll_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class epoll_container : public proton::io::container_impl_base {
epoll_container(const std::string& id);
~epoll_container();

// Pull in base class functions here so that name search finds all the overloads
using standard_container::stop;
using standard_container::connect;
using standard_container::listen;

proton::returned<proton::connection> connect(
const std::string& addr, const proton::connection_options& opts) OVERRIDE;

Expand Down Expand Up @@ -134,6 +139,9 @@ class epoll_container : public proton::io::container_impl_base {
std::atomic<uint64_t> count_;
};

// FIXME aconway 2016-06-07: Unfinished
void schedule(proton::duration, std::function<void()>) OVERRIDE { throw std::logic_error("FIXME"); }
void schedule(proton::duration, proton::void_function0&) OVERRIDE { throw std::logic_error("FIXME"); }
atomic_link_namer link_namer;

private:
Expand Down Expand Up @@ -244,8 +252,8 @@ class epoll_event_loop : public proton::event_loop {
return true;
}

bool inject(proton::inject_handler& h) OVERRIDE {
return inject(std::bind(&proton::inject_handler::on_inject, &h));
bool inject(proton::void_function0& f) OVERRIDE {
return inject([&f]() { f(); });
}

jobs pop_all() {
Expand Down
108 changes: 108 additions & 0 deletions examples/cpp/scheduled_send.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
*
* 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 "options.hpp"

#include <proton/default_container.hpp>
#include <proton/messaging_handler.hpp>

#include <iostream>

#include "fake_cpp11.hpp"

// Send messages at a constant rate one per interval. cancel after a timeout.
class scheduled_sender : public proton::messaging_handler {
private:
std::string url;
proton::sender sender;
proton::duration interval, timeout;
bool ready, canceled;

public:

scheduled_sender(const std::string &s, double d, double t) :
url(s),
interval(int(d*proton::duration::SECOND.milliseconds())), // Send interval.
timeout(int(t*proton::duration::SECOND.milliseconds())), // Cancel after timeout.
ready(true), // Ready to send.
canceled(false) // Canceled.
{}

void on_container_start(proton::container &c) OVERRIDE {
sender = c.open_sender(url);
// Call this->cancel after timeout.
c.schedule(timeout, [this]() { this->cancel(); });
// Start regular ticks every interval.
c.schedule(interval, [this]() { this->tick(); });
}

void cancel() {
canceled = true;
sender.connection().close();
}

void tick() {
// Schedule the next tick unless we have been cancelled.
if (!canceled)
sender.container().schedule(interval, [this]() { this->tick(); });
if (sender.credit() > 0) // Only send if we have credit
send();
else
ready = true; // Set the ready flag, send as soon as we get credit.
}

void on_sendable(proton::sender &) OVERRIDE {
if (ready) // We have been ticked since the last send.
send();
}

void send() {
std::cout << "send" << std::endl;
sender.send(proton::message("ping"));
ready = false;
}
};


int main(int argc, char **argv) {
std::string address("127.0.0.1:5672/examples");
double interval = 1.0;
double timeout = 5.0;

example::options opts(argc, argv);

opts.add_value(address, 'a', "address", "connect and send to URL", "URL");
opts.add_value(interval, 'i', "interval", "send a message every INTERVAL seconds", "INTERVAL");
opts.add_value(timeout, 't', "timeout", "stop after T seconds", "T");

try {
opts.parse();
scheduled_sender h(address, interval, timeout);
proton::default_container(h).run();
return 0;
} catch (const example::bad_option& e) {
std::cout << opts << std::endl << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}

return 1;
}
124 changes: 124 additions & 0 deletions examples/cpp/scheduled_send_03.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
*
* 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 "options.hpp"

#include <proton/default_container.hpp>
#include <proton/messaging_handler.hpp>

#include <iostream>

#include "fake_cpp11.hpp"

// Send messages at a constant rate one per interval. cancel after a timeout.
// This example uses only C++03 features.
class scheduled_sender : public proton::messaging_handler {
private:
std::string url;
proton::sender sender;
proton::duration interval, timeout;
bool ready, canceled;

struct tick_fn : public proton::void_function0 {
scheduled_sender& parent;
tick_fn(scheduled_sender& ss) : parent(ss) {}
void operator()() { parent.tick(); }
};

struct cancel_fn : public proton::void_function0 {
scheduled_sender& parent;
cancel_fn(scheduled_sender& ss) : parent(ss) {}
void operator()() { parent.cancel(); }
};

tick_fn do_tick;
cancel_fn do_cancel;

public:

scheduled_sender(const std::string &s, double d, double t) :
url(s),
interval(int(d*proton::duration::SECOND.milliseconds())), // Send interval.
timeout(int(t*proton::duration::SECOND.milliseconds())), // Cancel after timeout.
ready(true), // Ready to send.
canceled(false), // Canceled.
do_tick(*this),
do_cancel(*this)
{}

void on_container_start(proton::container &c) OVERRIDE {
sender = c.open_sender(url);
c.schedule(timeout, do_cancel); // Call this->cancel after timeout.
c.schedule(interval, do_tick); // Start regular ticks every interval.
}

void cancel() {
canceled = true;
sender.connection().close();
}

void tick() {
if (!canceled) {
sender.container().schedule(interval, do_tick); // Next tick
if (sender.credit() > 0) // Only send if we have credit
send();
else
ready = true; // Set the ready flag, send as soon as we get credit.
}
}

void on_sendable(proton::sender &) OVERRIDE {
if (ready) // We have been ticked since the last send.
send();
}

void send() {
std::cout << "send" << std::endl;
sender.send(proton::message("ping"));
ready = false;
}
};


int main(int argc, char **argv) {
std::string address("127.0.0.1:5672/examples");
double interval = 1.0;
double timeout = 5.0;

example::options opts(argc, argv);

opts.add_value(address, 'a', "address", "connect and send to URL", "URL");
opts.add_value(interval, 'i', "interval", "send a message every INTERVAL seconds", "INTERVAL");
opts.add_value(timeout, 't', "timeout", "stop after T seconds", "T");

try {
opts.parse();
scheduled_sender h(address, interval, timeout);
proton::default_container(h).run();
return 0;
} catch (const example::bad_option& e) {
std::cout << opts << std::endl << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}

return 1;
}