Skip to content

Commit

Permalink
FIX: Fix metadata not upgraded in C++
Browse files Browse the repository at this point in the history
  • Loading branch information
threecgreen committed Jun 21, 2024
1 parent af9c77c commit 62cc966
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
## 0.19.1 - TBD

### Enhancements
- Added `Upgrade()` method to `Metadata` to update the metadata fields according to a
`VersionUpgradePolicy`
- Added new publisher values for `XNAS.BASIC` and `XNAS.NLS`

### Bug fixes
- Fixed issue where `Metadata` wasn't upgraded when passing
`VersionUpgradePolicy::Upgrade`

## 0.19.0 - 2024-06-04

### Enhancements
Expand Down
3 changes: 3 additions & 0 deletions include/databento/dbn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ struct Metadata {
std::vector<std::string> not_found;
// Symbol mappings containing a native symbol and its mapping intervals.
std::vector<SymbolMapping> mappings;

// Upgrades the metadata according to `upgrade_policy` if necessary.
void Upgrade(VersionUpgradePolicy upgrade_policy);
};

inline bool operator==(const MappingInterval& lhs, const MappingInterval& rhs) {
Expand Down
11 changes: 10 additions & 1 deletion src/dbn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

#include <array>
#include <sstream> // ostringstream
#include <utility> // pair

#include "databento/constants.hpp"
#include "stream_op_helper.hpp"

namespace databento {

void Metadata::Upgrade(VersionUpgradePolicy upgrade_policy) {
if (version < kDbnVersion &&
upgrade_policy == VersionUpgradePolicy::Upgrade) {
version = kDbnVersion;
symbol_cstr_len = kSymbolCstrLen;
}
}

std::string ToString(const Metadata& metadata) { return MakeString(metadata); }
std::ostream& operator<<(std::ostream& stream, const Metadata& metadata) {
auto helper = StreamOpBuilder{stream}
Expand Down
1 change: 1 addition & 0 deletions src/dbn_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ databento::Metadata DbnDecoder::DecodeMetadata() {
buffer_idx_ = read_buffer_.size();
auto metadata = DbnDecoder::DecodeMetadataFields(version_, read_buffer_);
ts_out_ = metadata.ts_out;
metadata.Upgrade(upgrade_policy_);
return metadata;
}

Expand Down
1 change: 1 addition & 0 deletions src/live_blocking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ databento::Metadata LiveBlocking::Start() {
auto metadata =
DbnDecoder::DecodeMetadataFields(version_and_size.first, meta_buffer);
version_ = metadata.version;
metadata.Upgrade(upgrade_policy_);
return metadata;
}

Expand Down
2 changes: 1 addition & 1 deletion test/src/dbn_decoder_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ TEST_F(DbnDecoderTests, TestDecodeDefinitionUpgrade) {
const Metadata ch_metadata = channel_target_->DecodeMetadata();
const Metadata f_metadata = file_target_->DecodeMetadata();
EXPECT_EQ(ch_metadata, f_metadata);
EXPECT_EQ(ch_metadata.version, 1);
EXPECT_EQ(ch_metadata.version, 2);
EXPECT_EQ(ch_metadata.dataset, dataset::kXnasItch);
EXPECT_EQ(ch_metadata.schema, Schema::Definition);
EXPECT_EQ(ch_metadata.start.time_since_epoch().count(), 1633305600000000000);
Expand Down
38 changes: 22 additions & 16 deletions test/src/live_blocking_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>
#include <mutex> // lock_guard, mutex, unique_lock
#include <thread> // this_thread
#include <utility>
#include <vector>

#include "databento/constants.hpp" // dataset
Expand Down Expand Up @@ -55,23 +56,28 @@ TEST_F(LiveBlockingTests, TestAuthentication) {
.BuildBlocking();
}

TEST_F(LiveBlockingTests, TestStart) {
TEST_F(LiveBlockingTests, TestStartAndUpgrade) {
constexpr auto kTsOut = true;
const mock::MockLsgServer mock_server{dataset::kGlbxMdp3, kTsOut,
[](mock::MockLsgServer& self) {
self.Accept();
self.Authenticate();
self.Start();
}};

LiveBlocking target = builder_.SetAddress(kLocalhost, mock_server.Port())
.SetSendTsOut(kTsOut)
.SetDataset(dataset::kGlbxMdp3)
.BuildBlocking();
const auto metadata = target.Start();
EXPECT_EQ(metadata.version, 1);
EXPECT_TRUE(metadata.has_mixed_schema);
EXPECT_EQ(metadata.dataset, dataset::kGlbxMdp3);
for (const auto policy_and_version :
{std::make_pair(VersionUpgradePolicy::AsIs, 1),
std::make_pair(VersionUpgradePolicy::Upgrade, 2)}) {
const mock::MockLsgServer mock_server{dataset::kGlbxMdp3, kTsOut,
[](mock::MockLsgServer& self) {
self.Accept();
self.Authenticate();
self.Start();
}};

LiveBlocking target = builder_.SetAddress(kLocalhost, mock_server.Port())
.SetSendTsOut(kTsOut)
.SetDataset(dataset::kGlbxMdp3)
.SetUpgradePolicy(policy_and_version.first)
.BuildBlocking();
const auto metadata = target.Start();
EXPECT_EQ(metadata.version, policy_and_version.second);
EXPECT_TRUE(metadata.has_mixed_schema);
EXPECT_EQ(metadata.dataset, dataset::kGlbxMdp3);
}
}

TEST_F(LiveBlockingTests, TestSubscribe) {
Expand Down

0 comments on commit 62cc966

Please sign in to comment.