| 1 | use Test::Morescip-perl cpan Search-Elasticsearch-Client-1_0 6.81 Test/More/; |
| 2 | use Test::Deepscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 Test/Deep/; |
| 3 | use strictscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 strict/; |
| 4 | use warningsscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 warnings/; |
| 5 | use libscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 lib/ 't/lib'; |
| 6 | |
| 7 | $ENVscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/`%ENV`.{ES_VERSION} = '1_0'; |
| 8 | my $es = do "es_sync.pl" or diescip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/die().( $@scip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/`$@`. || $!scip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/`$!`. ); |
| 9 | |
| 10 | $es->indicesscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/indices().->deletescip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/delete().( index => '_all' ); |
| 11 | |
| 12 | test_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/test_flush().( |
| 13 | "max count", # |
| 14 | { max_count => 3 }, # |
| 15 | 1, 2, 0, 1, 2, 0, 1, 2, 0, 1 |
| 16 | ); |
| 17 | |
| 18 | test_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/test_flush().( |
| 19 | "max size", # |
| 20 | { max_size => 95 }, # |
| 21 | 1, 2, 3, 0, 1, 2, 3, 0, 1, 2 |
| 22 | ); |
| 23 | |
| 24 | test_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/test_flush().( |
| 25 | "max size > max_count", |
| 26 | { max_size => 95, max_count => 3 }, |
| 27 | 1, 2, 0, 1, 2, 0, 1, 2, 0, 1 |
| 28 | ); |
| 29 | |
| 30 | test_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/test_flush().( |
| 31 | "max size < max_count", |
| 32 | { max_size => 95, max_count => 5 }, |
| 33 | 1, 2, 3, 0, 1, 2, 3, 0, 1, 2 |
| 34 | ); |
| 35 | |
| 36 | test_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/test_flush().( |
| 37 | "max size = 0, max_count", |
| 38 | { max_size => 0, max_count => 5 }, |
| 39 | 1, 2, 3, 4, 0, 1, 2, 3, 4, 0 |
| 40 | ); |
| 41 | |
| 42 | test_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/test_flush().( |
| 43 | "max count = 0, max_size", |
| 44 | { max_size => 95, max_count => 0 }, |
| 45 | 1, 2, 3, 0, 1, 2, 3, 0, 1, 2 |
| 46 | ); |
| 47 | |
| 48 | test_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/test_flush().( |
| 49 | "max count = 0, max_size = 0", |
| 50 | { max_size => 0, max_count => 0 }, |
| 51 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 |
| 52 | ); |
| 53 | |
| 54 | test_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/test_flush().( |
| 55 | "max_count = 5, max_time = 5", |
| 56 | { max_count => 5, max_time => 5 }, |
| 57 | 1, 2, 0, 1, 2, 3, 4, 0, 0, 1 |
| 58 | ); |
| 59 | |
| 60 | done_testing; |
| 61 | |
| 62 | $es->indicesscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/indices().->deletescip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/delete().( index => 'test' ); |
| 63 | |
| 64 | #=================================== |
| 65 | sub test_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/test_flush(). { |
| 66 | #=================================== |
| 67 | my $title = shiftscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/shift().; |
| 68 | my $params = shiftscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/shift().; |
| 69 | my $b = $es->bulk_helperscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/bulk_helper().( |
| 70 | %$params, |
| 71 | index => 'test', |
| 72 | type => 'test' |
| 73 | ); |
| 74 | |
| 75 | my @seq = @_scip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/`@_`.; |
| 76 | |
| 77 | $es->indicesscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/indices().->deletescip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/delete().( index => 'test', ignore => 404 ); |
| 78 | $es->indicesscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/indices().->createscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/create().( index => 'test' ); |
| 79 | $es->clusterscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/cluster().->healthscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/health().( wait_for_status => 'yellow' ); |
| 80 | |
| 81 | for my $i ( 10 .. 19 ) { |
| 82 | |
| 83 | # sleep on 12 or 18 if max_time specified |
| 84 | if ( $params->{max_time} && ( $i == 12 || $i == 18 ) ) { |
| 85 | $b->_last_flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/_last_flush().( timescip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/time(). - $params->{max_time} - 1 ); |
| 86 | } |
| 87 | $b->indexscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/index().( { id => $i, source => {} } ); |
| 88 | isscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/is(). $b->_buffer_countscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/_buffer_count()., shiftscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/shift(). @seq, "$title - " . ( $i - 9 ); |
| 89 | } |
| 90 | $b->flushscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/flush().; |
| 91 | isscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/is(). $b->_buffer_countscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/_buffer_count()., 0, "$title - final flush"; |
| 92 | $es->indicesscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/indices().->refreshscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/refresh().; |
| 93 | isscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/is(). $es->countscip-perl cpan Search-Elasticsearch-Client-1_0 6.81 main/count().->{count}, 10, "$title - all docs indexed"; |
| 94 | |
| 95 | } |