Commit Graph

209 Commits

Author SHA1 Message Date
Avi Kivity
35f29dcdb4 fstream: add read-until-end tests without knowning the file size beforehand 2015-07-12 16:52:24 +03:00
Gleb Natapov
d0003e4f29 rpc: handler smart pointer return value from rpc handler
Currently if rpc handler returns smart pointer rpc will try to serialize
the pointer object as opposite to an object the ptr is pointing to.
This patch fixes it by serializing real object instead of a pointer.
2015-07-02 16:46:23 +03:00
Avi Kivity
7e66cc02e1 tests: close file in fileiotest 2015-06-28 20:40:37 +03:00
Nadav Har'El
7327e246c1 tests: convert fileiotest.cc to Boost test case
convert fileiotest.cc to Boost test case, making it easier to see what
is being tested, and to add more file io tests.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-06-28 12:35:03 +03:00
Avi Kivity
6ce39d8399 tests: move a semaphore test from futures_test to semaphore_test 2015-06-22 19:14:05 +03:00
Tomasz Grabiec
61992f84c5 core: Introduce repeat()
It's like do_until(), but the stop condition is calculated by the
callback instead of being supplied separately.
2015-06-22 09:08:38 +02:00
Avi Kivity
d9bfbe55c8 core: introduce shared_mutex class
Similar to std::shared_mutex, allows shared and exclusive locking of a
resource (also known as a reader/writer lock).  This implementation is
strictly FIFO.
2015-06-21 20:28:43 +03:00
Avi Kivity
439b9c848a tests: fix fstream_test misuse of shared_ptr
'static shared_ptr' causes the shared_ptr to be destroyed on a cpu other
than the one it was constructed on, which is illegal.
2015-06-20 12:02:00 +03:00
Avi Kivity
535928c643 tests: fix fstream_test use-after-free 2015-06-20 11:43:14 +03:00
Avi Kivity
1c8ee4e160 tests: convert foreign_ptr_test to SEASTAR_TEST_CASE
Makes it pass.
2015-06-20 11:29:53 +03:00
Avi Kivity
32ede23303 tests: remove obsolete test-reactor test 2015-06-20 11:17:28 +03:00
Avi Kivity
39218c32f7 core: extend do_with() to support multiple parameters
do_with(1, 2, 3, [] (int& v1, int& v2, int& v3) {
      return make_ready_future<int>(v1 + v2 + v3);
  });
2015-06-19 20:24:56 +03:00
Gleb Natapov
56193079a4 tests: add one more semaphore test
Test that wait with timeout and without work on the same semaphore
simultaneously.
2015-06-18 12:35:27 +03:00
Tomasz Grabiec
cf42e4c1a4 core: Fix enable_lw_shared_from_this<T>::shared_from_this() const
Compilation failed when shared_from_this() was called on a const object.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
2015-06-16 20:32:08 +03:00
Pekka Enberg
194cb68c8b tests: add thread-in-thread test case 2015-06-16 17:11:50 +03:00
Gleb Natapov
50b18a56cd test: add semaphore test 2015-06-14 16:03:46 +03:00
Gleb Natapov
1b2bf57a2b move timer out of reactor.hh to its own header 2015-06-14 16:02:16 +03:00
Raphael S. Carvalho
d864da71fc core: avoid fsyncing output stream twice
For some reason, I added a fsync call when the file underlying the
stream gets truncated. That happens when flushing a file, which
size isn't aligned to the requested DMA buffer.
Instead, fsync should only be called when closing the stream, so this
patch changes the code to do that.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-06-08 11:59:22 +03:00
Avi Kivity
27d9446f77 future: fix false-positive when a promise tied to a future that lost its state is destroyed
When a promise that still tracks its future is destroyed, but after
future::get() or future::then() was called, the promise thinks it was
destroyed before generating a value, and fails an assertion.

Fix be detaching the promise from the future as soon as get() or then()
remove the value.
2015-06-06 13:47:44 +03:00
Avi Kivity
3986ad6a11 thread: add seastar::async()
Following std::async(), seastar::async(func) causes func to be executed
in a seastar thread, where it can block using future<>::get().  Whatever
func returns is converted to a future, and returned as async()s return
value.
2015-06-04 20:57:00 +03:00
Amnon Heiman
38a22d9cd8 json: float and double support
This change how the json formatter handle float and adds double support.
float and double conversion will throw exceptions when try to convert
inf or nan.

It also contains tests for both float and double including inf, -inf and
nan for both float and double.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-06-03 10:01:00 +03:00
Avi Kivity
f9dd73d57f tests: make httpd test wait for continuations to execute
The reactor may defer them at will.
2015-06-02 15:12:10 +03:00
Avi Kivity
06dd2899f5 tests: convert httpd tests to SEASTAR_TEST_CASE
Some of them use continuations.
2015-06-02 15:12:10 +03:00
Avi Kivity
919260f3bd tests: ensure continuation is executed
The reactor is free not to inline continuations, so run checks inside
the continuation.
2015-06-02 15:12:10 +03:00
Avi Kivity
1b52ca1bef tests: memcache ascii parser: fix use-after-free
The input stream needs to be kept alive until we're done reading.
2015-06-02 15:12:10 +03:00
Gleb Natapov
c5077ce99b tests: add missing header 2015-05-31 15:24:00 +03:00
Vlad Zolotarov
796c203d68 core: remove #include "reactor.hh" from future-util.hh
When future-util.hh is included in files included in reactor.hh (e.g. file.hh).

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-26 15:15:28 +03:00
Amnon Heiman
6d6872063d http: simplify using the parameters in the request
The parameters in the request holds the path parameters. The current
implementation based on unorder_map has a few downside:

1. Because path parameters are sometime used to mark a file path and
they can extend to multiple url section (may contain /) the value will
always contain the leading slash. Though this is true for files, for
the common case, it would be easier to return the value without it.

2. The []operator of the hash map is non const, this mean that it cannot
be used in the common case where the request object is passed as a const
reference.

3. There is no exists method in an ordered_map - Usually query
parameters are mandatory, still it is usefull to have an easy way of
testing if a parameter is found.

This series wrap the unordered_map implementation in a manner more
suitable for the request.

The [] operator will be const and retrun a copy of the parameter value
without the leading slash.

The at method will keep the old meaning. For clearer code, a path method
was added to indicate that the return value has a leading slash.

A set method is used for assignment.

Older code will continue to work without changes.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-05-25 15:47:56 +03:00
Nadav Har'El
c5f61666d3 input_stream::consume() overhaul
Our input_stream::consume() mechanism allows feeding data from an input
stream into a consumer, piece by piece, until the consumer doesn't want
any more. It currently assumed the input can block (when reading from disk),
but the consumption is assumed to be immediate. This patch adds support for
blocking in the consumption function: The consumer now returns a future
which it promises to fulfill after consuming the given buffer.

This patch goes further by somewhat simplifying (?) the interface of the
consumer. Instead of receiving a mysterious "done" lambda the consumer
is supposed to call when done (doesn't want any more input), the consumer
now returns a future<optional<temporary_buffer<char>>, which means:

1. The future is fulfilled when the consumer is done with this buffer
   and either wants more - or wants to stop.

2. If the consumer wants to stop, it returns the *remaining* part of the
   buffer it didn't want to process (this will be pushed back into the
   input stream).

3. If the consumer is not done, and wants to consume more, it returns an
   unset optional.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-05-19 19:33:18 +03:00
Avi Kivity
1cf95e4bd8 Merge branch 'thread' of github.com:cloudius-systems/seastar-dev
This patchset adds thread support to seastar.  Threads can use the normal
seastar API, and may also "block" by calling future<>::get() on an
unavailable future.  Synchronous and asynchronous code may be intermixed.

Threads may not issue blocking operating system calls.
2015-05-18 15:27:22 +03:00
Avi Kivity
6223e88653 tests: add thread context switch timing test 2015-05-17 15:57:11 +03:00
Avi Kivity
7a309c07f5 tests: add basic thread test 2015-05-17 15:57:11 +03:00
Nadav Har'El
902d5b21ca sleep: Fix use-after-free in sleep()
The implementation of sleep() looks like a game of Seastar golf - doing
something in the minimum number of lines possible :-) Unfortunately, it
looks very clever, but not quite right. sleep() usually works correctly,
but the sanitizer (in the debug build) catches a use after free.

The problem was that we delete an object which contains a timer which
contains the callback (and std::function) - from inside this callback.

The workaround in this patch is to use our future chaining to only delete
the sleeper object after its future became ready - and at that point, none
of the sleeper object or code is needed any more.

This patch also includes a regression test for this issue. The test looks
silly (just sleeps and checks nothing), but in the debugging build it
failed (with a sanitizer reporting use-after-free) before this patch.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-05-14 11:26:58 +03:00
Avi Kivity
f3c8994535 distributed: add map_reduce() variant accepting an initial value
Separating the initial value (and accumulator) from the reducer function
can result in simpler invocations.

Unfortunately, the name conflicts with another variant, so we have to name
the method map_reduce0.
2015-05-12 16:57:50 +03:00
Avi Kivity
211c77bf52 shared_ptr: add const support for lw_shared_ptr 2015-05-06 11:41:33 +03:00
Avi Kivity
a28f0efd9a sstring: add iterator range constructor 2015-04-30 15:03:27 +03:00
Avi Kivity
d45e0ebd4a tests: add shared_ptr tests for const support
Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-04-29 12:32:54 +03:00
Pekka Enberg
066a37ad21 shared_ptr: Make shared_ptr work with foreign_ptr
The foreign_ptr wrapper needs 'element_type' to be present in
shared_ptr to be able to access the data.

Fixes the following compilation failure when trying to use shared_ptr
with foreign_ptr:

  In file included from tests/foreign_ptr_test.cc:24:0:
  ./core/distributed.hh: In instantiation of ‘class foreign_ptr<shared_ptr<basic_sstring<char, unsigned int, 15u> > >’:
  tests/foreign_ptr_test.cc:28:54:   required from here
  ./core/distributed.hh:272:56: error: no type named ‘element_type’ in ‘class shared_ptr<basic_sstring<char, unsigned int, 15u> >’
       using element_type = typename PtrType::element_type;

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-04-27 14:39:12 +03:00
Amnon Heiman
8a0538a218 http: fix query parameter parsing of last parameter
When serving a request with multiple query parameters the last parameter
was parsed incorectly.

This fix the issue and add a test to verify it

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-04-21 10:29:14 +03:00
Avi Kivity
b8f310870a tests: add map_reduce() test 2015-04-14 15:13:15 +03:00
Tomasz Grabiec
3a211c4db5 tests: Move seatar-boost test framework to a separate compilation unit
So that it's compiled only once and not for every test. This change
reduced recompilation time for a dummy test module from 40 seconds to
4 on my laptop.

This change also makes it now possible to pass seastar framework command
line arguments to every test using this framework.
2015-04-10 19:34:04 +02:00
Tomasz Grabiec
e87f76ac46 tests: Fix deadlock in ~test_runner
If the engine exits premauterly the _task exchanger may be occupied by
a pending task in which case give() will block indefinitely. Fix by
using interruption.
2015-04-10 19:34:04 +02:00
Tomasz Grabiec
026d169638 tests: exchanger: Add support for interrupting the parties 2015-04-10 19:34:03 +02:00
Amnon Heiman
53604f1fae Adding file transformers to http
Files transformers are used to replace file content before retrieving
it. Specifically, it is used to return swagger definition files with the
host and protocol replaced.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-04-05 09:53:33 +03:00
Amnon Heiman
04b5bad2b7 Adding insert replace and erase to sstring
The boost::replace_all uses insert and erase to perform a change, those
method are missing from sstring.

Following the std:string implemntation the implementation of both
functionalities is based on the replace method, either as c string
replace or with templated iterators.

Not all the variation of insert, replace and erase where added, but it
will be possible to add them in the future if needed by calling the
existing functionality.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-04-05 09:51:28 +03:00
Amnon Heiman
6512d7f7fb http support query parameter and url encoding
Http url encode query parameters by adding a question mark after the uri
with pairs of key=value items.

All values in the url are url decoded.

This add the url encoding and query parameters support

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
950d921df3 Http server handlers to use future
The http server handlers can sometimes need to perform async operation,
specifically, when reading files from the disk.  To support async
behavior the handlers handle function will return a future, that will be
propagate back, when the future will be ready it will return the reply
to be sent.

When switching from direct function call to future, there is also a need
to switch from references to pointers.

Note that while the request will be discarded, the reply will be
propagate back via the future to the caller.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
0faf9cbb56 Adding back, find_last_of and append to sstring
This adds the back method that return a reference or const reference to
the last char in an sstring.

find_last_of, which return the index of the last occurance of a char in
the string.

And append with append C string to a string.

The logic and definition are similiar to the std::string.

Note that following the std::string definition, calling back on an empty
string is forbiden and the results are undefined.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Shlomi Livne
cbf972c135 tests: set BOOST_TEST_SUITE to the test file name instead of the generic "seastar-tests"
Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-03-29 11:54:01 +03:00
Tomasz Grabiec
4dc8a6a09c test: distrubuted_test: Test that constructor arguments are copied on each core 2015-03-25 09:39:34 +01:00