Skip to content

Commit

Permalink
Fixed crash when trying to add key after compile [Issue 92] (#103)
Browse files Browse the repository at this point in the history
* Fixed crash when trying to add key after compile [Issue 92]

* Specify the memory limit in unit test.
  • Loading branch information
amit-cliqz authored Sep 13, 2018
1 parent db85ff9 commit c1343d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions keyvi/include/keyvi/dictionary/dictionary_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class DictionaryCompiler final {
DictionaryCompiler(const DictionaryCompiler& that) = delete;

void Add(const std::string& input_key, typename ValueStoreT::value_t value = ValueStoreT::no_value) {
if (generator_) {
throw compiler_exception("You're not supposed to add more data once compilation is done!");
}

size_of_keys_ += input_key.size();
sorter_.push_back(key_value_t(std::move(input_key), RegisterValue(value)));
}
Expand Down
11 changes: 11 additions & 0 deletions keyvi/tests/keyvi/dictionary/dictionary_compiler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(DeleteUnsupported, SorterT, sorter_types) {
BOOST_CHECK_THROW(compiler.Delete("aa"), compiler_exception);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(MultipleKeyUpdateAndCompile, SorterT, sorter_types) {
keyvi::dictionary::DictionaryCompiler<fsa::internal::SparseArrayPersistence<uint16_t>, fsa::internal::JsonValueStore,
SorterT>
compiler(keyvi::util::parameters_t({{"memory_limit_mb", "10"}}));

compiler.Add("a", "1");
compiler.Add("a", "1");
compiler.Compile();
BOOST_CHECK_THROW(compiler.Add("a", "1"), compiler_exception);
}

BOOST_AUTO_TEST_SUITE_END()

} /* namespace dictionary */
Expand Down

0 comments on commit c1343d9

Please sign in to comment.