storage_test.cc 1.0 KB
Newer Older
S
superjom 已提交
1
#include "visualdl/storage/storage.h"
S
superjom 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

#include <glog/logging.h>
#include <gtest/gtest.h>

namespace visualdl {
using namespace std;

class MemoryStorageTest : public ::testing::Test {
public:
  void SetUp() override { storage_.SetStorage("./tmp"); }

  MemoryStorage storage_;
};

TEST_F(MemoryStorageTest, SetStorage) {
  string dir = "./tmp";
  storage_.SetStorage(dir);

  ASSERT_EQ(storage_.data().dir(), dir);
}

TEST_F(MemoryStorageTest, AddTablet) {
  // TODO need to escape tag as name
  string tag = "add%20tag0";
  storage_.NewTablet(tag, -1);

  auto* tablet = storage_.tablet(tag);

  ASSERT_TRUE(tablet != nullptr);
  ASSERT_EQ(tablet->tag(), tag);
}

TEST_F(MemoryStorageTest, PersistToDisk) {
35 36
  storage_.SetStorage("./tmp");
  CHECK(!storage_.data().dir().empty());
S
superjom 已提交
37 38 39 40 41 42 43 44 45 46 47 48
  string tag = "add%20tag0";
  storage_.NewTablet(tag, -1);

  storage_.PersistToDisk();

  MemoryStorage other;
  other.LoadFromDisk("./tmp");
  ASSERT_EQ(other.data().SerializeAsString(),
            storage_.data().SerializeAsString());
}

}  // namespace visualdl