Fix tests
This commit is contained in:
parent
3f97a13493
commit
1c94c59a24
src
tests/unit
@ -23,7 +23,6 @@
|
||||
#include "storage/v3/key_store.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/shard_operation_result.hpp"
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Our communication layer and query engine don't mix
|
||||
|
@ -46,6 +46,8 @@ struct ShardError {
|
||||
// TODO Maybe add category
|
||||
std::string message;
|
||||
std::string source;
|
||||
|
||||
inline friend bool operator==(const ShardError &lhs, const ShardError &rhs) { return lhs.code == rhs.code; }
|
||||
};
|
||||
|
||||
#define SHARD_ERROR(...) memgraph::storage::v3::ShardError(__VA_ARGS__, fmt::format("{}:{}", __FILE__, __LINE__))
|
||||
|
@ -579,7 +579,7 @@ TEST_P(StorageV3, VertexDeleteSerializationError) {
|
||||
EXPECT_EQ(CountVertices(acc2, View::NEW), 1U);
|
||||
auto res = acc2.DeleteVertex(&*vertex);
|
||||
ASSERT_TRUE(res.HasError());
|
||||
ASSERT_EQ(res.GetError(), Error::SERIALIZATION_ERROR);
|
||||
ASSERT_EQ(res.GetError(), SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR));
|
||||
EXPECT_EQ(CountVertices(acc2, View::OLD), 1U);
|
||||
EXPECT_EQ(CountVertices(acc2, View::NEW), 1U);
|
||||
acc2.AdvanceCommand();
|
||||
@ -660,12 +660,11 @@ TEST_P(StorageV3, VertexDeleteSpecialCases) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TError, typename TResultHolder>
|
||||
void AssertErrorInVariant(TResultHolder &holder, TError error_type) {
|
||||
ASSERT_TRUE(holder.HasError());
|
||||
const auto error = holder.GetError();
|
||||
ASSERT_TRUE(std::holds_alternative<TError>(error));
|
||||
ASSERT_EQ(std::get<TError>(error), error_type);
|
||||
template <typename T>
|
||||
void AssertShardErrorEqual(const ShardResult<T> &lhs, const ShardError &rhs) {
|
||||
ASSERT_TRUE(lhs.HasError());
|
||||
const auto error = lhs.GetError();
|
||||
ASSERT_EQ(error, rhs);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(hicpp-special-member-functions)
|
||||
@ -711,20 +710,20 @@ TEST_P(StorageV3, VertexDeleteLabel) {
|
||||
|
||||
// Check whether label 5 exists
|
||||
ASSERT_FALSE(vertex->HasLabel(label5, View::OLD).GetValue());
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->Labels(View::OLD)->size(), 0);
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Try to add the label
|
||||
{
|
||||
auto ret = vertex->AddLabelAndValidate(label5);
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
// Try to remove the label
|
||||
{
|
||||
auto ret = vertex->RemoveLabelAndValidate(label5);
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
acc.Abort();
|
||||
@ -779,33 +778,33 @@ TEST_P(StorageV3, VertexDeleteLabel) {
|
||||
|
||||
// Check whether label 5 exists
|
||||
ASSERT_TRUE(vertex->HasLabel(label5, View::OLD).GetValue());
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
{
|
||||
auto labels = vertex->Labels(View::OLD).GetValue();
|
||||
ASSERT_EQ(labels.size(), 1);
|
||||
ASSERT_EQ(labels[0], label5);
|
||||
}
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Advance command
|
||||
acc.AdvanceCommand();
|
||||
|
||||
// Check whether label 5 exists
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::OLD).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Labels(View::OLD).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::OLD).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->Labels(View::OLD).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Try to add the label
|
||||
{
|
||||
auto ret = vertex->AddLabelAndValidate(label5);
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
// Try to remove the label
|
||||
{
|
||||
auto ret = vertex->RemoveLabelAndValidate(label5);
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
acc.Abort();
|
||||
@ -855,14 +854,14 @@ TEST_P(StorageV3, VertexDeleteProperty) {
|
||||
|
||||
// Check whether label 5 exists
|
||||
ASSERT_TRUE(vertex->GetProperty(property5, View::OLD)->IsNull());
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->Properties(View::OLD)->size(), 0);
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Try to set the property5
|
||||
{
|
||||
auto ret = vertex->SetPropertyAndValidate(property5, PropertyValue("haihai"));
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
acc.Abort();
|
||||
@ -918,27 +917,27 @@ TEST_P(StorageV3, VertexDeleteProperty) {
|
||||
|
||||
// Check whether property 5 exists
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::OLD)->ValueString(), "nandare");
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
{
|
||||
auto properties = vertex->Properties(View::OLD).GetValue();
|
||||
ASSERT_EQ(properties.size(), 1);
|
||||
ASSERT_EQ(properties[property5].ValueString(), "nandare");
|
||||
}
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Advance command
|
||||
acc.AdvanceCommand();
|
||||
|
||||
// Check whether property 5 exists
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::OLD).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Properties(View::OLD).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::OLD).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->Properties(View::OLD).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Try to set the property
|
||||
{
|
||||
auto ret = vertex->SetPropertyAndValidate(property5, PropertyValue("haihai"));
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
acc.Abort();
|
||||
@ -1371,7 +1370,7 @@ TEST_P(StorageV3, VertexLabelSerializationError) {
|
||||
|
||||
{
|
||||
auto res = vertex->AddLabelAndValidate(label1);
|
||||
AssertErrorInVariant(res, Error::SERIALIZATION_ERROR);
|
||||
AssertShardErrorEqual(res, SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1865,7 +1864,7 @@ TEST_P(StorageV3, VertexPropertySerializationError) {
|
||||
|
||||
{
|
||||
auto res = vertex->SetPropertyAndValidate(property2, PropertyValue("nandare"));
|
||||
AssertErrorInVariant(res, Error::SERIALIZATION_ERROR);
|
||||
AssertShardErrorEqual(res, SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2255,14 +2254,14 @@ TEST_P(StorageV3, VertexNonexistentLabelPropertyEdgeAPI) {
|
||||
auto vertex = CreateVertexAndValidate(acc, {}, PropertyValue{0}, {});
|
||||
|
||||
// Check state before (OLD view).
|
||||
ASSERT_EQ(vertex.Labels(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.Labels(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
|
||||
// Check state before (NEW view).
|
||||
ASSERT_EQ(vertex.Labels(View::NEW)->size(), 0);
|
||||
@ -2282,14 +2281,14 @@ TEST_P(StorageV3, VertexNonexistentLabelPropertyEdgeAPI) {
|
||||
.HasValue());
|
||||
|
||||
// Check state after (OLD view).
|
||||
ASSERT_EQ(vertex.Labels(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.Labels(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
|
||||
// Check state after (NEW view).
|
||||
ASSERT_EQ(vertex.Labels(View::NEW)->size(), 1);
|
||||
@ -2657,42 +2656,31 @@ TEST_P(StorageV3, TestCreateVertexAndValidate) {
|
||||
|
||||
ASSERT_TRUE(vertex2.HasError());
|
||||
auto error = vertex2.GetError();
|
||||
auto error_ptr = std::get_if<memgraph::storage::v3::Error>(&error);
|
||||
ASSERT_TRUE(error_ptr);
|
||||
ASSERT_TRUE(*error_ptr == storage::v3::Error::VERTEX_ALREADY_INSERTED);
|
||||
ASSERT_TRUE(error.code == storage::v3::ErrorCode::VERTEX_ALREADY_INSERTED);
|
||||
}
|
||||
{
|
||||
auto acc = store.Access(GetNextHlc());
|
||||
auto vertex = acc.CreateVertexAndValidate({primary_label}, {PropertyValue{0}}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, primary_label));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
|
||||
}
|
||||
{
|
||||
auto acc = store.Access(GetNextHlc());
|
||||
auto vertex = acc.CreateVertexAndValidate({primary_label}, {PropertyValue{0}}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, primary_label));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
|
||||
}
|
||||
{
|
||||
auto acc = store.Access(GetNextHlc());
|
||||
auto vertex = acc.CreateVertexAndValidate({}, {}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PRIMARY_PROPERTIES_UNDEFINED, primary_label));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED));
|
||||
}
|
||||
{
|
||||
auto acc = store.Access(GetNextHlc());
|
||||
auto vertex = acc.CreateVertexAndValidate({}, {PropertyValue{"test"}}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE, primary_label,
|
||||
{primary_property, common::SchemaType::INT}, PropertyValue("test")));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
|
||||
}
|
||||
}
|
||||
} // namespace memgraph::storage::v3::tests
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "storage/v3/name_id_mapper.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/shard.hpp"
|
||||
#include "storage/v3/shard_operation_result.hpp"
|
||||
|
||||
namespace memgraph::storage::v3::tests {
|
||||
using testing::UnorderedElementsAre;
|
||||
@ -39,7 +38,7 @@ class StorageEdgeTest : public ::testing::TestWithParam<bool> {
|
||||
return store.NameToEdgeType(edge_type_name);
|
||||
}
|
||||
|
||||
static ShardOperationResult<VertexAccessor> CreateVertex(Shard::Accessor &acc, const PropertyValue &key) {
|
||||
static ShardResult<VertexAccessor> CreateVertex(Shard::Accessor &acc, const PropertyValue &key) {
|
||||
return acc.CreateVertexAndValidate({}, {key}, {});
|
||||
}
|
||||
|
||||
@ -3243,7 +3242,7 @@ TEST_P(StorageEdgeTest, VertexDetachDeleteSingleCommit) {
|
||||
{
|
||||
auto ret = acc.DeleteVertex(&vertex_from.value());
|
||||
ASSERT_TRUE(ret.HasError());
|
||||
ASSERT_EQ(ret.GetError(), Error::VERTEX_HAS_EDGES);
|
||||
ASSERT_EQ(ret.GetError(), SHARD_ERROR(ErrorCode::VERTEX_HAS_EDGES));
|
||||
}
|
||||
|
||||
// Detach delete vertex
|
||||
@ -3256,8 +3255,8 @@ TEST_P(StorageEdgeTest, VertexDetachDeleteSingleCommit) {
|
||||
// Check edges
|
||||
ASSERT_EQ(vertex_from->InEdges(View::OLD)->size(), 0);
|
||||
ASSERT_EQ(*vertex_from->InDegree(View::OLD), 0);
|
||||
ASSERT_EQ(vertex_from->InEdges(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex_from->InDegree(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex_from->InEdges(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex_from->InDegree(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
{
|
||||
auto ret = vertex_from->OutEdges(View::OLD);
|
||||
ASSERT_TRUE(ret.HasValue());
|
||||
@ -3270,8 +3269,8 @@ TEST_P(StorageEdgeTest, VertexDetachDeleteSingleCommit) {
|
||||
ASSERT_EQ(e.FromVertex(), from_id);
|
||||
ASSERT_EQ(e.ToVertex(), to_id);
|
||||
}
|
||||
ASSERT_EQ(vertex_from->OutEdges(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex_from->OutDegree(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex_from->OutEdges(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex_from->OutDegree(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
{
|
||||
auto ret = vertex_to->InEdges(View::OLD);
|
||||
ASSERT_TRUE(ret.HasValue());
|
||||
|
@ -162,9 +162,8 @@ class SchemaValidatorTest : public testing::Test {
|
||||
|
||||
PropertyId NameToProperty(const std::string &name) { return PropertyId::FromUint(id_mapper_.NameToId(name)); }
|
||||
|
||||
protected:
|
||||
Schemas schemas;
|
||||
SchemaValidator schema_validator{schemas};
|
||||
SchemaValidator schema_validator{schemas, id_mapper_};
|
||||
PropertyId prop_string{NameToProperty("prop1")};
|
||||
PropertyId prop_int{NameToProperty("prop2")};
|
||||
PropertyId prop_duration{NameToProperty("prop3")};
|
||||
@ -180,50 +179,43 @@ TEST_F(SchemaValidatorTest, TestSchemaValidateVertexCreate) {
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateVertexCreate(NameToLabel("test"), {}, {PropertyValue(1)});
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::NO_SCHEMA_DEFINED_FOR_LABEL, NameToLabel("test")));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL));
|
||||
}
|
||||
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateVertexCreate(label2, {}, {});
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PRIMARY_PROPERTIES_UNDEFINED, label2));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED));
|
||||
}
|
||||
// Validate wrong secondary label
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateVertexCreate(label1, {label1}, {PropertyValue("test")});
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, label1));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
|
||||
}
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateVertexCreate(label1, {label2}, {PropertyValue("test")});
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, label2));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
|
||||
}
|
||||
// Validate wrong property type
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateVertexCreate(label1, {}, {PropertyValue(1)});
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE, label1,
|
||||
schema_prop_string, PropertyValue(1)));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
|
||||
}
|
||||
{
|
||||
const auto schema_violation =
|
||||
schema_validator.ValidateVertexCreate(label2, {}, {PropertyValue("test"), PropertyValue(12), PropertyValue(1)});
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE, label2,
|
||||
schema_prop_duration, PropertyValue(1)));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
|
||||
}
|
||||
{
|
||||
const auto wrong_prop = PropertyValue(TemporalData(TemporalType::Date, 1234));
|
||||
const auto schema_violation =
|
||||
schema_validator.ValidateVertexCreate(label2, {}, {PropertyValue("test"), PropertyValue(12), wrong_prop});
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE, label2,
|
||||
schema_prop_duration, wrong_prop));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
|
||||
}
|
||||
// Passing validations
|
||||
EXPECT_EQ(schema_validator.ValidateVertexCreate(label1, {}, {PropertyValue("test")}), std::nullopt);
|
||||
@ -245,14 +237,12 @@ TEST_F(SchemaValidatorTest, TestSchemaValidatePropertyUpdate) {
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidatePropertyUpdate(label1, prop_string);
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_KEY, label1,
|
||||
schema_prop_string));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
|
||||
}
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidatePropertyUpdate(label2, prop_duration);
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_KEY, label2,
|
||||
schema_prop_duration));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
|
||||
}
|
||||
EXPECT_EQ(schema_validator.ValidatePropertyUpdate(label1, prop_int), std::nullopt);
|
||||
EXPECT_EQ(schema_validator.ValidatePropertyUpdate(label1, prop_duration), std::nullopt);
|
||||
@ -264,14 +254,12 @@ TEST_F(SchemaValidatorTest, TestSchemaValidatePropertyUpdateLabel) {
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateLabelUpdate(label1);
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_LABEL, label1));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
|
||||
}
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateLabelUpdate(label2);
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_LABEL, label2));
|
||||
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
|
||||
}
|
||||
EXPECT_EQ(schema_validator.ValidateLabelUpdate(NameToLabel("test")), std::nullopt);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ TEST_F(StorageV3Accessor, TestPrimaryLabel) {
|
||||
ASSERT_TRUE(vertex.PrimaryLabel(View::OLD).HasError());
|
||||
const auto error_primary_label = vertex.PrimaryLabel(View::OLD).GetError();
|
||||
ASSERT_FALSE(vertex.PrimaryLabel(View::NEW).HasError());
|
||||
EXPECT_EQ(error_primary_label, Error::NONEXISTENT_OBJECT);
|
||||
EXPECT_EQ(error_primary_label, SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
}
|
||||
{
|
||||
auto acc = storage.Access(GetNextHlc());
|
||||
@ -127,9 +127,7 @@ TEST_F(StorageV3Accessor, TestAddLabels) {
|
||||
const auto label1 = NameToLabelId("label");
|
||||
auto vertex = acc.CreateVertexAndValidate({label1}, {PropertyValue{2}}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, label1));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
|
||||
}
|
||||
{
|
||||
auto acc = storage.Access(GetNextHlc());
|
||||
@ -138,9 +136,7 @@ TEST_F(StorageV3Accessor, TestAddLabels) {
|
||||
ASSERT_TRUE(vertex.HasValue());
|
||||
const auto schema_violation = vertex->AddLabelAndValidate(label1);
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(schema_violation.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(schema_violation.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_LABEL, label1));
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,9 +180,7 @@ TEST_F(StorageV3Accessor, TestRemoveLabels) {
|
||||
auto vertex = CreateVertexAndValidate(acc, {}, PropertyValue{2});
|
||||
const auto res1 = vertex.RemoveLabelAndValidate(primary_label);
|
||||
ASSERT_TRUE(res1.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(res1.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(res1.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_LABEL, primary_label));
|
||||
EXPECT_EQ(res1.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,20 +199,14 @@ TEST_F(StorageV3Accessor, TestSetKeysAndProperties) {
|
||||
auto vertex = CreateVertexAndValidate(acc, {}, PropertyValue{1});
|
||||
const auto res = vertex.SetPropertyAndValidate(primary_property, PropertyValue(1));
|
||||
ASSERT_TRUE(res.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(res.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(res.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_KEY, primary_label,
|
||||
SchemaProperty{primary_property, common::SchemaType::INT}));
|
||||
EXPECT_EQ(res.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
|
||||
}
|
||||
{
|
||||
auto acc = storage.Access(GetNextHlc());
|
||||
auto vertex = CreateVertexAndValidate(acc, {}, PropertyValue{2});
|
||||
const auto res = vertex.SetPropertyAndValidate(primary_property, PropertyValue());
|
||||
ASSERT_TRUE(res.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(res.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(res.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_KEY, primary_label,
|
||||
SchemaProperty{primary_property, common::SchemaType::INT}));
|
||||
EXPECT_EQ(res.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user