Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
code
pfabric
Commits
8f9d50ce
Commit
8f9d50ce
authored
Dec 07, 2017
by
Philipp Götze
Browse files
Added some test cases for NVMTable based on RDBTable
parent
d331641a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/table/NVMTable.hpp
View file @
8f9d50ce
...
...
@@ -51,7 +51,6 @@
#include "table/BaseTable.hpp"
#include "table/TableInfo.hpp"
namespace
pfabric
{
//TODO: Maybe the pmem device path prefix should be a CMake variable?
...
...
@@ -136,7 +135,8 @@ class NVMIterator {
public:
static_assert
(
detail
::
is_tuple
<
RecordType
>::
value
,
"Value type must be a pfabric::Tuple"
);
using
TupleType
=
typename
RecordType
::
Base
;
using
Predicate
=
std
::
function
<
bool
(
const
PTuple
<
TupleType
,
KeyType
>
&
)
>
;
// using Predicate = std::function<bool(const PTuple<TupleType, KeyType> &)>;
using
Predicate
=
std
::
function
<
bool
(
const
RecordType
&
)
>
;
using
PTableType
=
PTable
<
TupleType
,
KeyType
>
;
explicit
NVMIterator
()
{
...
...
@@ -145,13 +145,13 @@ class NVMIterator {
explicit
NVMIterator
(
typename
PTableType
::
iterator
&&
_iter
,
typename
PTableType
::
iterator
&&
_end
,
Predicate
_pred
)
:
iter
(
std
::
move
(
_iter
)),
end
(
std
::
move
(
_end
)),
pred
(
_pred
)
{
while
(
isValid
()
&&
!
pred
(
*
iter
))
while
(
isValid
()
&&
!
pred
(
*
(
*
iter
)
.
createTuple
())
)
iter
++
;
}
NVMIterator
&
operator
++
()
{
iter
++
;
while
(
isValid
()
&&
!
pred
(
*
iter
))
while
(
isValid
()
&&
!
pred
(
*
(
*
iter
)
.
createTuple
())
)
iter
++
;
return
*
this
;
}
...
...
@@ -261,8 +261,8 @@ class NVMTable : public BaseTable {
* \param rec the actual tuple
*****************************************************************************/
void
insert
(
KeyType
key
,
const
RecordType
&
rec
)
noexcept
(
false
)
{
pTable
->
insert
(
key
,
rec
.
data
());
notifyObservers
(
rec
,
TableParams
::
Insert
,
TableParams
::
Immediate
);
pTable
->
insert
(
key
,
rec
.
data
());
notifyObservers
(
rec
,
TableParams
::
Insert
,
TableParams
::
Immediate
);
}
/************************************************************************//**
...
...
@@ -354,9 +354,12 @@ class NVMTable : public BaseTable {
*****************************************************************************/
const
SmartPtr
<
RecordType
>
getByKey
(
KeyType
key
)
noexcept
(
false
)
{
//TODO: ugly, can we do better?
SmartPtr
<
RecordType
>
tptr
(
new
RecordType
(
*
pTable
->
getByKey
(
key
).
createTuple
()));
return
tptr
;
try
{
SmartPtr
<
RecordType
>
tptr
(
new
RecordType
(
*
pTable
->
getByKey
(
key
).
createTuple
()));
return
tptr
;
}
catch
(
ptable
::
PTableException
&
pex
)
{
throw
TableException
(
pex
.
what
());
}
}
/************************************************************************//**
...
...
@@ -395,7 +398,8 @@ class NVMTable : public BaseTable {
* \return a pair of iterators
*****************************************************************************/
TableIterator
select
()
{
auto
alwaysTrue
=
[](
const
PTuple
<
TupleType
,
KeyType
>
&
)
{
return
true
;
};
auto
alwaysTrue
=
[](
const
RecordType
&
)
{
return
true
;
};
// auto alwaysTrue = [](const PTuple<TupleType, KeyType> &) { return true; };
return
makeNVMIterator
<
RecordType
,
KeyType
>
(
std
::
move
(
pTable
->
begin
()),
std
::
move
(
pTable
->
end
()),
alwaysTrue
);
}
...
...
@@ -445,8 +449,7 @@ class NVMTable : public BaseTable {
}
private:
void
openOrCreateTable
(
const
TableInfo
&
tableInfo
)
/*throw(TableException)*/
{
void
openOrCreateTable
(
const
TableInfo
&
tableInfo
)
noexcept
(
false
)
{
std
::
string
path
=
pathPrefix
+
tableInfo
.
tableName
()
+
".db"
;
pool
<
root
>
pop
;
...
...
src/test/NVMTableTest.cpp
View file @
8f9d50ce
...
...
@@ -32,3 +32,70 @@ TEST_CASE("Creating a table with a given schema and inserting data",
}
testTable
->
drop
();
}
TEST_CASE
(
"Creating a table with a given schema and deleting data"
,
"[NVMTable]"
)
{
auto
testTable
=
std
::
make_shared
<
TableType
>
(
"MyTestTable2"
);
for
(
int
i
=
0
;
i
<
10000
;
i
++
)
{
auto
tp
=
MyTuple
((
unsigned
long
)
i
,
i
+
100
,
fmt
::
format
(
"String#{}"
,
i
),
i
/
100.0
);
testTable
->
insert
(
i
,
tp
);
}
REQUIRE
(
testTable
->
size
()
==
10000
);
for
(
int
i
=
0
;
i
<
10000
;
i
+=
100
)
testTable
->
deleteByKey
(
i
);
//TODO: REQUIRE(testTable->size() == 9900);
// check if the records were really deleted
for
(
int
i
=
0
;
i
<
10000
;
i
+=
100
)
{
try
{
auto
tp
=
testTable
->
getByKey
(
i
);
REQUIRE
(
false
);
}
catch
(
TableException
&
exc
)
{
// if the key wasn't found then an exception is raised
// which we can ignore here
}
}
testTable
->
drop
();
}
TEST_CASE
(
"scanning the whole table"
,
"[NVMTable]"
)
{
auto
testTable
=
std
::
make_shared
<
TableType
>
(
"MyTestTable7"
);
for
(
int
i
=
0
;
i
<
10000
;
i
++
)
{
auto
tp
=
MyTuple
((
unsigned
long
)
i
,
i
+
100
,
fmt
::
format
(
"String#{}"
,
i
),
i
/
100.0
);
testTable
->
insert
(
i
,
tp
);
}
REQUIRE
(
testTable
->
size
()
==
10000
);
unsigned
int
num
=
0
;
for
(
auto
iter
=
testTable
->
select
();
iter
.
isValid
();
++
iter
)
num
++
;
REQUIRE
(
num
==
testTable
->
size
());
testTable
->
drop
();
}
TEST_CASE
(
"scanning the table with a predicate"
,
"[NVMTable]"
)
{
auto
testTable
=
std
::
make_shared
<
TableType
>
(
"MyTestTable8"
);
for
(
int
i
=
0
;
i
<
10000
;
i
++
)
{
auto
tp
=
MyTuple
((
unsigned
long
)
i
,
i
+
100
,
fmt
::
format
(
"String#{}"
,
i
),
i
/
100.0
);
testTable
->
insert
(
i
,
tp
);
}
REQUIRE
(
testTable
->
size
()
==
10000
);
unsigned
int
num
=
0
;
{
auto
iter
=
testTable
->
select
(
[](
const
MyTuple
&
tp
)
{
return
get
<
0
>
(
tp
)
%
2
==
0
;
});
for
(;
iter
.
isValid
();
iter
++
)
{
REQUIRE
(
get
<
0
>
(
*
iter
)
%
2
==
0
);
num
++
;
}
REQUIRE
(
num
==
testTable
->
size
()
/
2
);
}
testTable
->
drop
();
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment