about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-29 20:17:19 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-29 20:17:48 +0000
commite5c2e2588d7ad2243afeabad67b3c951c5b66643 (patch)
tree76fa5a4687c53a73b0729b3e5268cbc17e6f977d /t
parent11a7b5403d3d3dda8266efa374336ca344288cfe (diff)
downloadpublic-inbox-e5c2e2588d7ad2243afeabad67b3c951c5b66643.tar.gz
Having multiple Xapian partitions is mostly pointless after
the initial import.  We can compact all the partitions into
one while keeping the skeleton separate.
Diffstat (limited to 't')
-rw-r--r--t/convert-compact.t57
1 files changed, 57 insertions, 0 deletions
diff --git a/t/convert-compact.t b/t/convert-compact.t
new file mode 100644
index 00000000..922ec9c2
--- /dev/null
+++ b/t/convert-compact.t
@@ -0,0 +1,57 @@
+# Copyright (C) 2018 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use warnings;
+use Test::More;
+use File::Temp qw/tempdir/;
+use PublicInbox::MIME;
+my @mods = qw(DBD::SQLite Search::Xapian);
+foreach my $mod (@mods) {
+        eval "require $mod";
+        plan skip_all => "$mod missing for convert-compact.t" if $@;
+}
+use PublicInbox::V2Writable;
+use PublicInbox::Import;
+my $tmpdir = tempdir('convert-compact-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my $ibx = {
+        mainrepo => "$tmpdir/v1",
+        name => 'test-v1',
+        -primary_address => 'test@example.com',
+};
+
+ok(PublicInbox::Import::run_die([qw(git init --bare -q), $ibx->{mainrepo}]),
+        'initialized v1 repo');
+$ibx = PublicInbox::Inbox->new($ibx);
+my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
+my $mime = PublicInbox::MIME->create(
+        header => [
+                From => 'a@example.com',
+                To => 'test@example.com',
+                Subject => 'this is a subject',
+                'Message-ID' => '<a-mid@b>',
+                Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
+        ],
+        body => "hello world\n",
+);
+ok($im->add($mime), 'added one message');
+$im->done;
+PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
+local $ENV{PATH} = "blib/script:$ENV{PATH}";
+open my $err, '>>', "$tmpdir/err.log" or die "open: err.log $!\n";
+open my $out, '>>', "$tmpdir/out.log" or die "open: out.log $!\n";
+my $rdr = { 1 => fileno($out), 2 => fileno($err) };
+
+my $cmd = [ 'public-inbox-compact', $ibx->{mainrepo} ];
+ok(PublicInbox::Import::run_die($cmd, undef, $rdr), 'v1 compact works');
+
+$cmd = [ 'public-inbox-convert', $ibx->{mainrepo}, "$tmpdir/v2" ];
+ok(PublicInbox::Import::run_die($cmd, undef, $rdr), 'convert works');
+
+$cmd = [ 'public-inbox-compact', "$tmpdir/v2" ];
+my $env = { NPROC => 2 };
+ok(PublicInbox::Import::run_die($cmd, $env, $rdr), 'v2 compact works');
+$ibx->{mainrepo} = "$tmpdir/v2";
+my $v2w = PublicInbox::V2Writable->new($ibx);
+is($v2w->{partitions}, 1, "only one partition in compacted repo");
+
+done_testing();