<commit_before>/**
 * This file is part of the CernVM File System.
 */

#include <gtest/gtest.h>

#include <session_context.h>

using namespace upload;
typedef SessionContext::Stats Stats;

class T_SessionContext : public ::testing::Test {};

TEST_F(T_SessionContext, BasicLifeCycle) {
  SessionContext ctx;
  EXPECT_TRUE(ctx.Initialize("http://my.repo.address:8080/api/v1",
                             "/path/to/the/session_file"));

  Stats stats = ctx.stats();

  EXPECT_EQ(stats.buckets_created, 0u);
  EXPECT_EQ(stats.buckets_committed, 0u);
  EXPECT_EQ(stats.objects_dispatched, 0u);
  EXPECT_EQ(stats.bytes_committed, 0u);
  EXPECT_EQ(stats.bytes_dispatched, 0u);

  EXPECT_TRUE(ctx.FinalizeSession());
}<commit_msg>T_SessionContext - add basic lifecycle test<commit_after>/**
 * This file is part of the CernVM File System.
 */

#include <gtest/gtest.h>

#include <session_context.h>

using namespace upload;

class SessionContextMocked : public SessionContext {
  virtual Future<bool>* DispatchObjectPack(ObjectPack* pack) {
    delete pack;  // Discard object pack

    // Just return a completed future saying everything is "fine" (TM)
    Future<bool>* future = new Future<bool>();
    future->Set(true);
    return future;
  }
};

typedef SessionContext::Stats Stats;

class T_SessionContext : public ::testing::Test {};

TEST_F(T_SessionContext, BasicLifeCycle) {
  SessionContextMocked ctx;
  EXPECT_TRUE(ctx.Initialize("http://my.repo.address:8080/api/v1",
                             "/path/to/the/session_file"));

  Stats stats = ctx.stats();

  EXPECT_EQ(stats.buckets_created, 0u);
  EXPECT_EQ(stats.buckets_committed, 0u);
  EXPECT_EQ(stats.objects_dispatched, 0u);
  EXPECT_EQ(stats.bytes_committed, 0u);
  EXPECT_EQ(stats.bytes_dispatched, 0u);

  ObjectPack::BucketHandle hd = ctx.NewBucket();
  stats = ctx.stats();
  EXPECT_EQ(stats.buckets_created, 1u);

  unsigned char buffer[4096];
  memset(buffer, 0, 4096);
  ObjectPack::AddToBucket(buffer, 4096, hd);

  shash::Any hash(shash::kSha1);
  EXPECT_TRUE(ctx.CommitBucket(ObjectPack::kCas, hash, hd));
  ctx.Dispatch();
  stats = ctx.stats();
  EXPECT_EQ(stats.buckets_committed, 1u);
  EXPECT_EQ(stats.bytes_committed, 4096u);
  EXPECT_EQ(stats.objects_dispatched, 1u);
  EXPECT_EQ(stats.bytes_dispatched, 4096u);

  EXPECT_TRUE(ctx.Finalize());
}
{'fraction_non_alphanumeric': 0.13187285223367698, 'fraction_numerical': 0.019329896907216496, 'mean_word_length': 4.5985576923076925, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, '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': '6628493', 'n_tokens_mistral': 851, 'n_tokens_neox': 812, 'n_words': 154}