<commit_before>//
// Copyright (c) 2014 The pblcache Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cache

import (
	"fmt"
	"github.com/lpabon/tm"
	"github.com/pblcache/pblcache/message"
	"github.com/pblcache/pblcache/tests"
	"math/rand"
	"sync"
	"testing"
	"time"
)

func TestNewCache(t *testing.T) {
	nc := message.NewNullTerminator()
	nc.Start()
	defer nc.Close()

	c := NewCache(8, 4096, nc.In)
	tests.Assert(t, c != nil)
	c.Close()
}

func TestCacheSimple(t *testing.T) {
	nc := message.NewNullTerminator()
	nc.Start()<commit_msg>cache: TestInvalidate<commit_after>//
// Copyright (c) 2014 The pblcache Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cache

import (
	"fmt"
	"github.com/lpabon/tm"
	"github.com/pblcache/pblcache/message"
	"github.com/pblcache/pblcache/tests"
	"math/rand"
	"sync"
	"testing"
	"time"
)

func TestNewCache(t *testing.T) {
	nc := message.NewNullTerminator()
	nc.Start()
	defer nc.Close()

	c := NewCache(8, 4096, nc.In)
	tests.Assert(t, c != nil)
	c.Close()
}

func TestInvalidateMultipleBlocks(t *testing.T) {
	nc := message.NewNullTerminator()
	nc.Start()
	defer nc.Close()

	c := NewCache(8, 4096, nc.In)
	tests.Assert(t, c != nil)
	defer c.Close()

	// Insert some values in the addressmap
	for i := uint64(0); i < 4; i++ {

		// The key is offset in bytes
		c.addressmap[i*4096] = i
	}

	// This value should still be on the addressmap
	c.addressmap[8*4096] = 8

	iopkt := &message.IoPkt{
		Offset:  0,
		Nblocks: 8,
	}

	c.Invalidate(iopkt)
	tests.Assert(t, c.stats.invalidations == uint64(iopkt.Nblocks))
	tests.Assert(t, c.stats.invalidatehits == 4)
	tests.Assert(t, c.addressmap[8*4096] == 8)
}

func TestCacheSimple(t *testing.T) {
	nc := message.NewNullTerminator()
	nc.Start()
{'fraction_non_alphanumeric': 0.13446286950252342, 'fraction_numerical': 0.020187454938716654, 'mean_word_length': 3.6954314720812182, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4397084', 'n_tokens_mistral': 996, 'n_tokens_neox': 951, 'n_words': 299}