Пример #1
0
void no_read(A4Input &in) {
    shared<InputStream> stream = in.get_stream();
    if (!stream) return;
    assert(stream->good());
    if (stream->error()) {
        ERROR("stream problem in no_read thread ", boost::this_thread::get_id());
    }
}
Пример #2
0
int main(int argc, char ** argv) {
    {
        A4Output a4o("test_thread.a4", "TestEvent");
        boost::thread t1(my_write, boost::ref(a4o));
        boost::thread t2(my_write, boost::ref(a4o));
        boost::thread t3(my_write, boost::ref(a4o));
        boost::thread t4(my_write, boost::ref(a4o));
        boost::thread t5(my_write, boost::ref(a4o));
        boost::thread t6(no_write, boost::ref(a4o));
        t1.join();
        t2.join();
        t3.join();
        t4.join();
        t5.join();
        t6.join();
    }
    {
        A4Input in;
        in.add_file("test_thread.a4", false);
        in.add_file("test_thread.a4", false);
        in.add_file("test_thread.a4", false);
        in.add_file("test_thread.a4", false);
        in.add_file("test_thread.a4", false);
        boost::thread t1(no_read, boost::ref(in));
        boost::thread t2(my_read, boost::ref(in));
        boost::thread t3(my_read, boost::ref(in));
        boost::thread t4(my_read, boost::ref(in));
        boost::thread t5(my_read, boost::ref(in));
        boost::thread t6(my_read, boost::ref(in));
        boost::thread t7(my_read, boost::ref(in));
        boost::thread t8(my_read, boost::ref(in));
        boost::thread t9(my_read, boost::ref(in));
        t1.join();
        t2.join();
        t3.join();
        t4.join();
        t5.join();
        t6.join();
        t7.join();
        t8.join();
        t9.join();
    }
}
Пример #3
0
int main(int argc, char ** argv) {
    const int N = 1000;
    {
        A4Output a4o("test_io.a4", "Event");

        shared<OutputStream> stream = a4o.get_stream();
        stream->set_compression(OutputStream::ZLIB, 1);

        Event e;
        for(int i = 0; i < N; i++) {
            e.set_event_number(i);
            stream->write(e);
        }
        EventStreamInfo m;
        m.set_total_events(N);
        stream->metadata(m);
    }
    {
        A4Input in;
        in.add_file("test_io.a4");
        Event e;
        const Event * te;
        shared<A4Message> msg;
        while (shared<InputStream> stream = in.get_stream()) {
            int cnt = 0;
            while (true) {
                if (stream->try_read(e)) {
                    te = &e;
                } else {
                    msg = stream->next();
                    if (not msg) break;
                    te = msg->as<Event>();
                }
                auto * me = stream->current_metadata()->as<EventStreamInfo>();
                assert(cnt++ == te->event_number());
                assert(me->total_events() == N);
            }
            if (stream->error()) throw "AJS";
        }
    }
}
Пример #4
0
void my_read(A4Input &in) {
    shared<InputStream> stream = in.get_stream();
    if (!stream) return;
    int cnt = 0;
    while (shared<A4Message> msg = stream->next()) {
        if (const TestEvent* te = msg->as<TestEvent>()) {
            assert((cnt++%N) == te->event_number());
        }
    }
    if (stream->error())
        ERROR("stream problem in thread ", boost::this_thread::get_id());
    assert(cnt == 5*N);
}