Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A start of transaction Role with some tests #126

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ test_requires 'Test::Exception' => 0;
test_requires 'Test::LWP::UserAgent' => 0;
test_requires 'Test::More' => 0.88;
test_requires 'XML::Simple' => 0;
test_requires 'Test::Modern' => 0;
test_requires 'Proc::Fork' => 0;

perl_version '5.014';

Expand Down
7 changes: 7 additions & 0 deletions lib/Attean/API/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ package Attean::API::BulkUpdatableStore 0.021 {
requires 'end_bulk_updates';
}

package Attean::API::TransactionalStore 0.021 {
use Moo::Role;

requires 'begin_transaction';
requires 'end_transaction';
}

1;

__END__
Expand Down
87 changes: 87 additions & 0 deletions lib/Test/Attean/MutableTransactionalQuadStore.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package Test::Attean::MutableTransactionalQuadStore;

use v5.14;
use warnings;
use Test::Roo::Role;
use Attean;
use Attean::RDF;
use Proc::Fork;
use Test::Modern;


requires 'create_store'; # create_store( quads => \@quads )
with 'Test::Attean::StoreCleanup';

test 'mutabletransactionalquadstore sequential' => sub {
my $self = shift;
my $q1 = quad(iri('s'), iri('p'), dtliteral('35', iri('http://www.w3.org/2001/XMLSchema#integer')), iri('g'));
my $store = $self->create_store(quads => [$q1]);
my $model = Attean::MutableQuadModel->new(store => $store);
my $objects = $model->objects(iri('s'), iri('p'), iri('g'));
does_ok($objects, 'Attean::API::Iterator');
my $count1 = $objects->next->value;
is($count1, 35, 'Correct initial count');
$model->remove_quad($q1);
is($model->size, 0);
my $cout1 = $count1 + 100;
my $q2 = quad(iri('s'), iri('p'), dtliteral($cout1, iri('http://www.w3.org/2001/XMLSchema#integer')), iri('g'));
$model->add_quad($q2);
is($model->size, 1);

# Now next to come around
my $object = $model->objects(iri('s'), iri('p'), iri('g'))->next;
does_ok($object, 'Attean::API::Term');
my $count2 = $object->value;
is($count2, $cout1, 'Correct count read back');
my $cout2 = $cout1 - 30;
$model->remove_quad($q2);
my $q3 = quad(iri('s'), iri('p'), dtliteral($cout2, iri('http://www.w3.org/2001/XMLSchema#integer')), iri('g'));
$model->add_quad($q3);
is($model->size, 1);
is($model->objects(iri('s'), iri('p'), iri('g'))->next->value, $cout2, 'Correct count read back');


$self->cleanup_store($store);
};


test 'mutabletransactionalquadstore lost update' => sub {
my $self = shift;
my $q1 = quad(iri('s'), iri('p'), dtliteral('35', iri('http://www.w3.org/2001/XMLSchema#integer')), iri('g'));
my $store = $self->create_store(quads => [$q1]);
my $model = Attean::MutableQuadModel->new(store => $store);

run_fork {
child {
my $objects = $model->objects(iri('s'), iri('p'), iri('g'));
does_ok($objects, 'Attean::API::Iterator');
my $count1 = $objects->next->value;
is($count1, 35, 'Correct initial count');
$model->remove_quad($q1);
is($model->size, 0);
my $cout1 = $count1 + 100;
my $q2 = quad(iri('s'), iri('p'), dtliteral($cout1, iri('http://www.w3.org/2001/XMLSchema#integer')), iri('g'));
$model->add_quad($q2);
is($model->size, 1);
};
child {
# Now next to come around
my $object = $model->objects(iri('s'), iri('p'), iri('g'))->next;
does_ok($object, 'Attean::API::Term');
my $count2 = $object->value;
my $cout1 = 135;
is($count2, $cout1, 'Correct count read back');
my $cout2 = $cout1 - 30;
my $q2 = quad(iri('s'), iri('p'), dtliteral($cout1, iri('http://www.w3.org/2001/XMLSchema#integer')), iri('g'));
$model->remove_quad($q2);
my $q3 = quad(iri('s'), iri('p'), dtliteral($cout2, iri('http://www.w3.org/2001/XMLSchema#integer')), iri('g'));
$model->add_quad($q3);
is($model->size, 1);
is($model->objects(iri('s'), iri('p'), iri('g'))->next->value, $cout2, 'Correct count read back');
}
};

$self->cleanup_store($store);
};

1;
18 changes: 18 additions & 0 deletions t/store-transaction.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use Test::Modern;
use Test::Roo;
use Attean;

use v5.14;

sub create_store {
my $self = shift;
my %args = @_;
my $store = Attean->get_store('Memory')->new();
$store->add_quad($args{quads}[0]);
return $store;
}

with 'Test::Attean::MutableTransactionalQuadStore';

run_me;
done_testing;