Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cppinttest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cppinttest
Commits
4ad86b5d
Commit
4ad86b5d
authored
3 years ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Test for server #170 (Updating datatype to list & add value)
parent
a89372aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#12828
passed
3 years ago
Stage: info
Stage: setup
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/CMakeLists.txt
+1
-0
1 addition, 0 deletions
test/CMakeLists.txt
test/test_issues.cpp
+147
-0
147 additions, 0 deletions
test/test_issues.cpp
test/test_transaction.cpp
+2
-1
2 additions, 1 deletion
test/test_transaction.cpp
with
150 additions
and
1 deletion
test/CMakeLists.txt
+
1
−
0
View file @
4ad86b5d
...
...
@@ -26,6 +26,7 @@ set(test_cases
test_transaction
test_list_properties
test_ccaosdb
test_issues
)
...
...
This diff is collapsed.
Click to expand it.
test/test_issues.cpp
0 → 100644
+
147
−
0
View file @
4ad86b5d
#include
"caosdb/connection.h"
// for Connection, ConnectionManager
#include
"caosdb/data_type.h"
// for AtomicDataType
#include
"caosdb/entity.h"
// for Entity, Messages, Message
#include
"caosdb/file_transmission/file_reader.h"
// for FileReader
#include
"caosdb/file_transmission/file_writer.h"
// for FileWriter
#include
"caosdb/message_code.h"
// for ENTITY_DOES_NOT_EXIST, Messag...
#include
"caosdb/status_code.h"
// for SUCCESS, StatusCode
#include
"caosdb/transaction.h"
// for Entity, Transaction,...
#include
"caosdb/transaction_status.h"
// for TransactionStatus, StatusCode
#include
<boost/filesystem/operations.hpp>
// for remove
#include
<boost/filesystem/path.hpp>
// for path
#include
<boost/filesystem/path_traits.hpp>
// for filesystem
#include
<boost/lexical_cast.hpp>
#include
<gtest/gtest-message.h>
// for Message
#include
<gtest/gtest-spi.h>
// for EXPECT_NONFATAL_FAILURE
#include
<gtest/gtest-test-part.h>
// for TestPartResult, SuiteApiResolver
#include
<gtest/gtest_pred_impl.h>
// for Test, EXPECT_EQ, AssertionResult
#include
<iostream>
#include
<memory>
// for unique_ptr, allocator, __shar...
#include
<string>
// for string
#include
<vector>
// for vector
namespace
fs
=
boost
::
filesystem
;
namespace
caosdb
::
transaction
{
using
caosdb
::
entity
::
AtomicDataType
;
using
caosdb
::
entity
::
Entity
;
using
caosdb
::
entity
::
Role
;
using
caosdb
::
entity
::
Value
;
class
test_issues
:
public
::
testing
::
Test
{
public:
// public utility functions
// ////////////////////////////////////////////////////////
/**
* Generate a vector with useful values for testing.
*/
template
<
typename
T
>
static
auto
generateValues
()
->
std
::
vector
<
T
>
{
std
::
vector
<
T
>
values
=
{
0
,
1
,
// (T)6.91629132943846e-310,
std
::
numeric_limits
<
T
>::
max
(),
std
::
numeric_limits
<
T
>::
min
(),
std
::
numeric_limits
<
T
>::
denorm_min
(),
std
::
numeric_limits
<
T
>::
lowest
(),
std
::
numeric_limits
<
T
>::
epsilon
()
// 0 for integers, but who cares?
};
return
values
;
}
template
<
typename
T
>
static
auto
getValueAs
(
const
Value
&
/*value*/
)
->
T
{
throw
std
::
logic_error
(
"Template not implemented for this type."
);
}
static
void
DeleteEntities
()
{
// delete all entities
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"FIND ENTITY WITH id > 99"
);
query_transaction
->
Execute
();
if
(
query_transaction
->
GetResultSet
().
size
()
>
0
)
{
std
::
cout
<<
"Cleanup: Deleting "
<<
query_transaction
->
GetResultSet
().
size
()
<<
" entities."
<<
std
::
endl
;
auto
delete_transaction
(
connection
->
CreateTransaction
());
for
(
const
Entity
&
entity
:
query_transaction
->
GetResultSet
())
{
delete_transaction
->
DeleteById
(
entity
.
GetId
());
}
delete_transaction
->
Execute
();
}
}
protected
:
fs
::
path
test_upload_file_1
;
fs
::
path
test_download_file_1
;
// Fixture methods //////////////////////////////////////////////////////////
void
SetUp
()
override
{
DeleteEntities
();
test_upload_file_1
=
fs
::
path
(
"test_upload_file_1_delete_me.dat"
);
test_download_file_1
=
fs
::
path
(
"test_download_file_1_delete_me.dat"
);
// fill the file that shall be uploaded
FileWriter
writer
(
test_upload_file_1
);
std
::
string
buffer
(
1024
,
'c'
);
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
writer
.
write
(
buffer
);
}
}
void
TearDown
()
override
{
// delete files
fs
::
remove
(
test_upload_file_1
);
fs
::
remove
(
test_download_file_1
);
DeleteEntities
();
}
};
/*
* test error-prone updates
*/
TEST_F
(
test_issues
,
server_issue_170
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
// Insert original
auto
insert_transaction
(
connection
->
CreateTransaction
());
Entity
original
;
original
.
SetRole
(
Role
::
PROPERTY
);
original
.
SetName
(
"Prop 1"
);
original
.
SetDataType
(
AtomicDataType
::
DOUBLE
);
insert_transaction
->
InsertEntity
(
&
original
);
insert_transaction
->
ExecuteAsynchronously
();
auto
insert_status
=
insert_transaction
->
WaitForIt
();
ASSERT_TRUE
(
insert_status
.
IsTerminated
());
ASSERT_FALSE
(
insert_status
.
IsError
());
const
auto
&
insert_result_set
=
insert_transaction
->
GetResultSet
();
auto
id
=
insert_result_set
.
at
(
0
).
GetId
();
EXPECT_FALSE
(
id
.
empty
());
// Retrieve original with ID
auto
retrieve_transaction
(
connection
->
CreateTransaction
());
retrieve_transaction
->
RetrieveById
(
id
);
retrieve_transaction
->
Execute
();
auto
update_entity
(
retrieve_transaction
->
GetResultSet
().
at
(
0
));
// UPDATE
auto
update_transaction
(
connection
->
CreateTransaction
());
update_entity
.
SetDataType
(
AtomicDataType
::
INTEGER
,
true
);
update_entity
.
SetValue
(
std
::
vector
<
int32_t
>
{
1
,
1
,
2
,
3
,
5
,
8
,
13
});
EXPECT_NONFATAL_FAILURE
(
{
update_transaction
->
UpdateEntity
(
&
update_entity
);
update_transaction
->
ExecuteAsynchronously
();
auto
update_status
=
update_transaction
->
WaitForIt
();
EXPECT_TRUE
(
update_status
.
IsTerminated
());
EXPECT_FALSE
(
update_status
.
IsError
());
},
"update_status.IsError"
);
}
}
// namespace caosdb::transaction
This diff is collapsed.
Click to expand it.
test/test_transaction.cpp
+
2
−
1
View file @
4ad86b5d
/*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
...
...
This diff is collapsed.
Click to expand it.
Timm Fitschen
@timm
mentioned in merge request
caosdb-server!28 (merged)
·
3 years ago
mentioned in merge request
caosdb-server!28 (merged)
mentioned in merge request caosdb-server!28
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment