46 #include <sys/types.h> 54 #ifdef XAPIAN_HAS_REMOTE_BACKEND 62 if (mkdir(path.c_str(), 0700) == -1 && errno != EEXIST) {
63 FAIL_TEST(
"Can't make temporary directory");
75 static size_t do_read(
int fd,
char * p,
size_t desired)
79 ssize_t c = read(fd, p, desired);
80 if (c == 0)
return total;
82 if (errno == EINTR)
continue;
92 static void do_write(
int fd,
const char * p,
size_t n)
95 ssize_t c = write(fd, p, n);
97 if (errno == EINTR)
continue;
111 FAIL_TEST(
"Open failed (when opening '" << srcpath <<
"')");
114 FD fdout(
open(destpath.c_str(), O_WRONLY | O_CREAT | O_TRUNC |
O_BINARY, 0666));
116 FAIL_TEST(
"Open failed (when creating '" << destpath <<
"')");
119 const int BUFSIZE = 1024;
121 size_t total_bytes = 0;
123 size_t thiscopy = tocopy > BUFSIZE ? BUFSIZE : tocopy;
124 size_t bytes =
do_read(fdin, buf, thiscopy);
125 if (thiscopy != bytes) {
126 FAIL_TEST(
"Couldn't read desired number of bytes from changeset");
129 total_bytes += bytes;
133 if (
close(fdout) == -1)
143 int expected_changesets,
144 int expected_fullcopies,
145 bool expected_changed,
146 bool full_copy =
false)
148 FD fd(
open(changesetpath.c_str(), O_WRONLY | O_CREAT | O_TRUNC |
O_BINARY, 0666));
150 FAIL_TEST(
"Open failed (when creating a new changeset file at '" 151 << changesetpath <<
"')");
166 int expected_changesets,
167 int expected_fullcopies,
168 bool expected_changed)
172 FAIL_TEST(
"Open failed (when reading changeset file at '" 173 << changesetpath <<
"')");
180 bool client_changed =
false;
186 client_changed =
true;
191 client_changed =
true;
204 const string & tempdir,
205 int expected_changesets,
206 int expected_fullcopies,
207 bool expected_changed,
208 bool full_copy =
false)
210 string changesetpath = tempdir +
"/changeset";
239 #define set_max_changesets(N) setenv("XAPIAN_MAX_CHANGESETS", #N, 1) 248 #define UNSET_MAX_CHANGESETS_AFTERWARDS unset_max_changesets_helper_ ezlxq 257 #ifdef XAPIAN_HAS_REMOTE_BACKEND 259 string tempdir =
".replicatmp";
272 string replicapath = tempdir +
"/replica";
282 int count =
replicate(master, replica, tempdir, 0, 1,
true);
291 count =
replicate(master, replica, tempdir, 0, 0,
false);
303 int count =
replicate(master, replica, tempdir, 0, 0,
false);
315 count =
replicate(master, replica, tempdir, 2, 0,
true);
336 #ifdef XAPIAN_HAS_REMOTE_BACKEND 340 string tempdir =
".replicatmp";
349 string replicapath = tempdir +
"/replica";
353 string replica2path = tempdir +
"/replica2";
437 #ifdef XAPIAN_HAS_REMOTE_BACKEND 441 const string & tempdir,
442 int expected_changesets,
443 int expected_fullcopies,
444 bool expected_changed)
446 string changesetpath = tempdir +
"/changeset";
451 string brokenchangesetpath = tempdir +
"/changeset_broken";
455 while (len < filesize) {
456 copylen =
truncated_copy(changesetpath, brokenchangesetpath, len);
458 tout <<
"Trying replication with a changeset truncated to " << len <<
459 " bytes, from " << filesize <<
" bytes\n";
462 expected_changesets, expected_fullcopies,
464 if (len < 30 || len >= filesize - 10) {
471 if (len >= filesize - 10) {
481 #ifdef XAPIAN_HAS_REMOTE_BACKEND 483 string tempdir =
".replicatmp";
492 string replicapath = tempdir +
"/replica";
532 #ifdef XAPIAN_HAS_REMOTE_BACKEND 534 string tempdir =
".replicatmp";
543 string replicapath = tempdir +
"/replica";
555 int count =
replicate(master, replica, tempdir, 0, 1,
true);
568 count =
replicate(master, replica, tempdir, 1, 0,
true);
588 count =
replicate(master, replica, tempdir, 1, 0,
true);
610 count =
replicate(master, replica, tempdir, 0, 1,
true);
630 #ifdef XAPIAN_HAS_REMOTE_BACKEND 633 string tempdir =
".replicatmp";
642 string replicapath = tempdir +
"/replica";
654 int count =
replicate(master, replica, tempdir, 0, 1,
true);
667 count =
replicate(master, replica, tempdir, 1, 0,
true);
683 count =
replicate(master, replica, tempdir, 1, 0,
true);
699 count =
replicate(master, replica, tempdir, 1, 0,
true);
723 count =
replicate(master, replica, tempdir, 1, 0,
true);
739 count =
replicate(master, replica, tempdir, 1, 0,
true);
762 #ifdef XAPIAN_HAS_REMOTE_BACKEND 764 string tempdir =
".replicatmp";
773 string replicapath = tempdir +
"/replica";
784 rm_rf(masterpath +
"1");
785 cp_R(masterpath, masterpath +
"1");
792 int count =
replicate(master, replica, tempdir, 0, 1,
true);
802 count =
replicate(master1, replica, tempdir, 0, 0,
false);
806 count =
replicate(master1, replica, tempdir, 0, 1,
true,
true);
813 count =
replicate(master, replica, tempdir, 2, 0,
true);
828 #ifdef XAPIAN_HAS_REMOTE_BACKEND 830 string tempdir =
".replicatmp";
838 string replicapath = tempdir +
"/replica";
855 int count =
replicate(master, replica, tempdir, 0, 1,
true);
865 string d = replicapath;
879 if (entry->
d_name[0] ==
'.')
continue;
884 int fd =
open(file.c_str(), O_WRONLY|O_TRUNC);
895 int count =
replicate(master, replica, tempdir, 0, 1,
true);
Xapian::docid add_document(const Xapian::Document &document)
Add a new document to the database.
static size_t check(const std::string &path, int opts=0, std::ostream *out=NULL)
Check the integrity of a database or database table.
void dbcheck(const Xapian::Database &db, Xapian::doccount expected_doccount, Xapian::docid expected_lastdocid)
Check consistency of database and statistics.
#define TEST(a)
Test a condition, without an additional explanation for failure.
This class is used to access a database, or a group of databases.
void set_read_fd(int fd)
Set the file descriptor to read changesets from.
unset_max_changesets_helper_()
int fullcopy_count
Number of times a full database copy was performed.
test database contents and consistency.
Access to a master database for replication.
static int apply_changeset(const string &changesetpath, Xapian::DatabaseReplica &replica, int expected_changesets, int expected_fullcopies, bool expected_changed)
Access to a database replica, for applying replication to it.
TermIterator allterms_end(const std::string &=std::string()) const
Corresponding end iterator to allterms_begin(prefix).
Xapian::docid get_lastdocid() const
Get the highest document id which has been used in the database.
Convert errno value to std::string, thread-safe if possible.
a generic test suite engine
struct dirent * readdir(DIR *)
C++ function versions of useful Unix commands.
WritableDatabase open()
Construct a WritableDatabase object for a new, empty InMemory database.
#define set_max_changesets(N)
Xapian::WritableDatabase get_writable_database_again()
include <dirent.h>, with alternative implementation for windows.
Utility functions for testing files.
Xapian::doccount get_doccount() const
Get the number of documents in the database.
std::string get_revision_info() const
Get a string describing the current revision of the replica.
include <sys/stat.h> with portability enhancements
static void check_equal_dbs(const string &masterpath, const string &replicapath)
Xapian::WritableDatabase get_named_writable_database(const std::string &name, const std::string &source)
test functionality of the Xapian API
void rm_rf(const string &filename)
Remove a directory and contents, just like the Unix "rm -rf" command.
void cp_R(const std::string &src, const std::string &dest)
Recursively copy a directory.
static int replicate(Xapian::DatabaseMaster &master, Xapian::DatabaseReplica &replica, const string &tempdir, int expected_changesets, int expected_fullcopies, bool expected_changed, bool full_copy=false)
Class for iterating over a list of terms.
static void do_write(int fd, const char *p, size_t n)
static size_t do_read(int fd, char *p, size_t desired)
string postlist_to_string(const Xapian::Database &db, const string &tname)
Convert the list of postings in a postlist to a string.
static off_t get_file_size(const string &path)
std::string get_named_writable_database_path(const std::string &name)
DIR * opendir(const char *)
This class provides read/write access to a database.
std::ostringstream tout
The debug printing stream.
void errno_to_string(int e, string &s)
~unset_max_changesets_helper_()
Public interfaces for the Xapian library.
bool apply_next_changeset(ReplicationInfo *info, double reader_close_time)
Read and apply the next changeset.
#define TEST_EXCEPTION(TYPE, CODE)
Check that CODE throws exactly Xapian exception TYPE.
Wrapper class around a file descriptor to avoid leaks.
Information about the steps involved in performing a replication.
int changeset_count
Number of changesets applied.
void commit()
Commit any pending modifications made to the database.
static void rmtmpdir(const string &path)
static void replicate_with_brokenness(Xapian::DatabaseMaster &master, Xapian::DatabaseReplica &replica, const string &tempdir, int expected_changesets, int expected_fullcopies, bool expected_changed)
Provide setenv() with compatibility versions.
TermIterator allterms_begin(const std::string &prefix=std::string()) const
An iterator which runs across all terms with a given prefix.
static void get_changeset(const string &changesetpath, Xapian::DatabaseMaster &master, Xapian::DatabaseReplica &replica, int expected_changesets, int expected_fullcopies, bool expected_changed, bool full_copy=false)
#define SKIP_TEST_FOR_BACKEND(B)
bool changed
True if and only if the replication corresponds to a change in the live version of the database...
void add_posting(const std::string &tname, Xapian::termpos tpos, Xapian::termcount wdfinc=1)
Add an occurrence of a term at a particular position.
#define FAIL_TEST(MSG)
Fail the current testcase with message MSG.
Replication support for Xapian databases.
Indicates a problem communicating with a remote database.
static void mktmpdir(const string &path)
Xapian-specific test helper functions and macros.
<unistd.h>, but with compat.
off_t file_size(const char *path)
Returns the size of a file.
void write_changesets_to_fd(int fd, const std::string &start_revision, ReplicationInfo *info) const
Write a set of changesets for upgrading the database to a file.
#define UNSET_MAX_CHANGESETS_AFTERWARDS
#define TEST_EQUAL(a, b)
Test for equality of two things.
void set_data(const std::string &data)
Set data stored in the document.
bool file_exists(const char *path)
Test if a file exists.
virtual void close()
Close the database.
include <fcntl.h>, but working around broken platforms.
DEFINE_TESTCASE(replicate1, replicas)
static off_t truncated_copy(const string &srcpath, const string &destpath, off_t tocopy)
A handle representing a document in a Xapian database.
std::string get_uuid() const
Get a UUID for the database.
void add_term(const std::string &tname, Xapian::termcount wdfinc=1)
Add a term to the document, without positional information.