/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: #ident "$Id$" /*====== This file is part of PerconaFT. Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. PerconaFT is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. PerconaFT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with PerconaFT. If not, see . ---------------------------------------- PerconaFT is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. PerconaFT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with PerconaFT. If not, see . ======= */ #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." #include "test.h" #include #include #include #include #include "loader/loader-internal.h" #include "memory.h" #include static int qsort_compare_ints (const void *a, const void *b) { int avalue = *(int*)a; int bvalue = *(int*)b; if (avaluebvalue) return +1; return 0; } static int compare_ints (DB* UU(desc), const DBT *akey, const DBT *bkey) { assert(akey->size==sizeof(int)); assert(bkey->size==sizeof(int)); return qsort_compare_ints(akey->data, bkey->data); } static void err_cb(DB *db UU(), int dbn UU(), int err UU(), DBT *key UU(), DBT *val UU(), void *extra UU()) { fprintf(stderr, "error in test"); abort(); } bool founddup; static void expect_dups_cb(DB *db UU(), int dbn UU(), int err UU(), DBT *key UU(), DBT *val UU(), void *extra UU()) { founddup=true; } static void test_merge_internal (int a[], int na, int b[], int nb, bool dups) { int *MALLOC_N(na+nb, ab); // the combined array a and b for (int i=0; ib[j]); j++; } else { assert(0); } } } } toku_free(cr); toku_free(ar); toku_free(br); toku_free(ab); ft_loader_destroy_error_callback(&bl.error_callback); } /* Test the basic merger. */ static void test_merge (void) { { int avals[]={1,2,3,4,5}; int *bvals = NULL; test_merge_internal(avals, 5, bvals, 0, false); test_merge_internal(bvals, 0, avals, 5, false); } { int avals[]={1,3,5,7}; int bvals[]={2,4}; test_merge_internal(avals, 4, bvals, 2, false); test_merge_internal(bvals, 2, avals, 4, false); } { int avals[]={1,2,3,5,6,7}; int bvals[]={2,4,5,6,8}; test_merge_internal(avals, 6, bvals, 5, true); test_merge_internal(bvals, 5, avals, 6, true); } } static void test_internal_mergesort_row_array (int a[], int n) { struct row *MALLOC_N(n, ar); for (int i=0; i= fs.n_temp_files); // destroy_rowset(&aset); // destroy_rowset(&bset); for (int i=0; i<2; i++) assert(fs.data_fidxs[i].idx != -1); ft_loader_fi_close_all(&bl.file_infos); QUEUE q; r = toku_queue_create(&q, 0xFFFFFFFF); // infinite queue. assert(r==0); r = merge_files(&fs, &bl, 0, dest_db, compare_ints, 0, q); CKERR(r); assert(fs.n_temp_files==0); DESCRIPTOR_S desc; toku_fill_dbt(&desc.dbt, "abcd", 4); int fd = open(output_name, O_RDWR | O_CREAT | O_BINARY, S_IRWXU|S_IRWXG|S_IRWXO); assert(fd>=0); r = toku_loader_write_ft_from_q_in_C(&bl, &desc, fd, 1000, q, size_est, 0, 0, 0, TOKU_DEFAULT_COMPRESSION_METHOD, 16); assert(r==0); destroy_merge_fileset(&fs); ft_loader_fi_destroy(&bl.file_infos, false); ft_loader_destroy_error_callback(&bl.error_callback); ft_loader_lock_destroy(&bl); // verify the dbfile verify_dbfile(10, sorted_keys, sorted_vals, output_name); r = toku_queue_destroy(q); assert(r==0); } /* Test to see if we can open temporary files. */ int test_main (int argc, const char *argv[]) { argc--; argv++; while (argc>0) { if (strcmp(argv[0],"-v")==0) { verbose=1; } else if (strcmp(argv[0],"-q")==0) { verbose=0; } else { break; } argc--; argv++; } const char* directory = TOKU_TEST_FILENAME; int r = toku_os_mkdir(directory, 0755); if (r!=0) CKERR2(errno, EEXIST); int templen = strlen(directory)+15; char tf_template[templen]; { int n = snprintf(tf_template, templen, "%s/tempXXXXXX", directory); assert (n>0 && n0 && n0 && n