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

optimize the implementation logic of TestSerializeReaderSet #332

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
50 changes: 50 additions & 0 deletions tests/fixtures/test_reader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

// Copyright 2024-present the vsag project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <string.h>

#include "vsag/binaryset.h"
#include "vsag/readerset.h"

namespace fixtures {

class TestReader : public vsag::Reader {
public:
TestReader(vsag::Binary binary) : binary_(binary) {
}

void
Read(uint64_t offset, uint64_t len, void* dest) override {
memcpy((char*)dest, binary_.data.get() + offset, len);
}

void
AsyncRead(uint64_t offset, uint64_t len, void* dest, vsag::CallBack callback) override {
Read(offset, len, dest);
callback(vsag::IOErrorCode::IO_SUCCESS, "success");
}

uint64_t
Size() const override {
return binary_.size;
}

private:
vsag::Binary binary_;
};

} // namespace fixtures
16 changes: 7 additions & 9 deletions tests/test_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "test_index.h"

#include "fixtures/test_logger.h"
#include "fixtures/test_reader.h"
#include "fixtures/thread_pool.h"
#include "simd/fp32_simd.h"

Expand Down Expand Up @@ -431,16 +432,13 @@ TestIndex::TestSerializeReaderSet(const IndexPtr& index_from,
const std::string& search_param,
const std::string& index_name,
bool expected_success) {
auto dir = fixtures::TempDir("serialize");
auto path = dir.GenerateRandomFile();
std::ofstream outfile(path, std::ios::out | std::ios::binary);
auto serialize_index = index_from->Serialize(outfile);
REQUIRE(serialize_index.has_value() == expected_success);
outfile.close();

vsag::ReaderSet rs;
auto reader = vsag::Factory::CreateLocalFileReader(path, 0, 0);
rs.Set(index_name, reader);
auto serialize_binary = index_from->Serialize();
REQUIRE(serialize_binary.has_value() == expected_success);
auto binary_set = serialize_binary.value();
for (const auto& key : binary_set.GetKeys()) {
rs.Set(key, std::make_shared<TestReader>(binary_set.Get(key)));
}
auto deserialize_index = index_to->Deserialize(rs);
REQUIRE(deserialize_index.has_value() == expected_success);

Expand Down
Loading