<commit_before>// Copyright (c) 2013, Cloudera, inc.

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

#include "cfile/block_cache.h"
#include "util/slice.h"

namespace kudu {
namespace cfile {

TEST(TestBlockCache, TestBasics) {
  const string DATUM_1("hello world");
  const string DATUM_2("goodbye world");

  BlockCache cache(1024);

  BlockCache::FileId id = cache.GenerateFileId();

  // Lookup something missing from cache
  {
    BlockCacheHandle handle;
    ASSERT_FALSE(cache.Lookup(id, 1, &handle));
    ASSERT_FALSE(handle.valid());
  }

  // Insert and re-lookup
  BlockCacheHandle inserted_handle;
  cache.Insert(id, 1, Slice(DATUM_1), &inserted_handle);
  ASSERT_TRUE(inserted_handle.valid());

  BlockCacheHandle retrieved_handle;
  ASSERT_TRUE(cache.Lookup(id, 1, &retrieved_handle));
  ASSERT_TRUE(retrieved_handle.valid());
  ASSERT_EQ(reinterpret_cast<const char *>(retrieved_handle.data().data()),
            DATUM_1.c_str());

  // Ensure that a lookup for a different offset doesn't<commit_msg>block_cache-test: need to strdup the data that's inserted to avoid invalid free<commit_after>// Copyright (c) 2013, Cloudera, inc.

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

#include "cfile/block_cache.h"
#include "util/slice.h"

namespace kudu {
namespace cfile {

TEST(TestBlockCache, TestBasics) {
  char *DATUM_1 = strdup("hello world");

  BlockCache cache(1024);

  BlockCache::FileId id = cache.GenerateFileId();

  // Lookup something missing from cache
  {
    BlockCacheHandle handle;
    ASSERT_FALSE(cache.Lookup(id, 1, &handle));
    ASSERT_FALSE(handle.valid());
  }

  // Insert and re-lookup
  BlockCacheHandle inserted_handle;
  cache.Insert(id, 1, Slice(DATUM_1), &inserted_handle);
  ASSERT_TRUE(inserted_handle.valid());

  BlockCacheHandle retrieved_handle;
  ASSERT_TRUE(cache.Lookup(id, 1, &retrieved_handle));
  ASSERT_TRUE(retrieved_handle.valid());
  ASSERT_EQ(reinterpret_cast<const char *>(retrieved_handle.data().data()),
            DATUM_1);

  // Ensure that a lookup for a different offset doesn't
{'fraction_non_alphanumeric': 0.12760795730228044, 'fraction_numerical': 0.014070839398350316, 'mean_word_length': 4.775910364145658, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7032878', 'n_tokens_mistral': 724, 'n_tokens_neox': 678, 'n_words': 152}