test_framework

package
v0.0.0-...-309f818 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// always emulate a slow hard disk. Cold be very slow!
	THROTTLING_ALWAYS = Throttling(1)
	// sometimes (2% of the time) emulate a slow hard disk.
	THROTTLING_SOMETIMES = Throttling(2)
	// never throttle output
	THROTTLING_NEVER = Throttling(3)
)
View Source
const (
	HANDLE_INPUT  = Handle(1)
	HANDLE_OUTPUT = Handle(2)
	HANDLE_SLICE  = Handle(3)
)

Variables

Class environment setup rule.

Throttling

View Source
var TEST_VERSION_CURRENT = util.VERSION_45

Use this constant then creating Analyzers and any other version-dependent stuff. NOTE: Change this when developmenet starts for new Lucene version:

Functions

func AfterSuite

func AfterSuite(t *testing.T)

func BeforeSuite

func BeforeSuite(t *testing.T)

func CheckIndex

func CheckIndex(dir store.Directory, crossCheckTermVectors bool) *index.CheckIndexStatus

func ClassRuleChain

func ClassRuleChain(rule ClassTestRule) *_ClassRuleChain

func CloseAfterSuite

func CloseAfterSuite(closer func() error)

Registers a Closeable resource that shold be closed after the suite completes.

func NewCloseableDirectory

func NewCloseableDirectory(dir BaseDirectoryWrapper, failureMarker *tutil.TestRuleMarkFailure) func() error

Attempts to close a BaseDirectoryWrapper

func NewDefaultIOContext

func NewDefaultIOContext(r *rand.Rand) store.IOContext

func NewField

func NewField(r *rand.Rand, name, value string, typ *docu.FieldType) *docu.Field

func NewIOContext

func NewIOContext(r *rand.Rand, oldContext store.IOContext) store.IOContext

func NewIndexWriterConfig

func NewIndexWriterConfig(v util.Version, a analysis.Analyzer) *index.IndexWriterConfig

Create a new index writer config with tutil.Random defaults

func NewNullInfoStream

func NewNullInfoStream() util.InfoStream

func NewSearcher

L1305 Create a new searcher over the reader. This searcher might randomly use threads

func NewTextField

func NewTextField(name, value string, stored bool) *docu.Field

L1064

func SuppressCodecs

func SuppressCodecs(name string)

func Test

func Test(t *testing.T, f func(t *T))

func TestRuleChain

func TestRuleChain(rule TestRule) *_RuleChain

Types

type BaseDirectoryWrapper

type BaseDirectoryWrapper interface {
	store.Directory
	IsOpen() bool
}

Calls check index on close. do NOT make any methods in this class synchronized, volatile do NOT import anything from the concurrency package. no randoms, no nothing.

func NewDirectory

func NewDirectory() BaseDirectoryWrapper

Returns a new Direcotry instance. Use this when the test does not care about the specific Directory implementation (most tests).

The Directory is wrapped with BaseDirectoryWrapper. This menas usually it will be picky, such as ensuring that you properly close it and all open files in your test. It will emulate some features of Windows, such as not allowing open files ot be overwritten.

type BaseDirectoryWrapperImpl

type BaseDirectoryWrapperImpl struct {
	store.Directory // our delegate in directory
	// contains filtered or unexported fields
}

func NewBaseDirectoryWrapper

func NewBaseDirectoryWrapper(delegate store.Directory) *BaseDirectoryWrapperImpl

func (*BaseDirectoryWrapperImpl) Close

func (dw *BaseDirectoryWrapperImpl) Close() error

func (*BaseDirectoryWrapperImpl) IsOpen

func (dw *BaseDirectoryWrapperImpl) IsOpen() bool

func (*BaseDirectoryWrapperImpl) String

func (dw *BaseDirectoryWrapperImpl) String() string

type ClassTestRule

type ClassTestRule interface {
	Before() error
	After() error
}

Workaround Junit's TestRule for class

type Failure

type Failure struct {
	// contains filtered or unexported fields
}

Objects that represent fail-lable conditions. Objects of a derived class are created and registered with teh mock directory. After register, each object will be invoked once for each first write of a file, giving the object a chance to throw an IO error.

func (*Failure) ClearDoFail

func (f *Failure) ClearDoFail()

func (*Failure) Reset

func (f *Failure) Reset() *Failure

reset should set the state of the failure to its default (freshly constructed) state. Reset is convenient for tests that want to create one failure object and then reuse it in mutiple cases. This, combined with the fact that Failure subclasses are often anonymous classes makes reset difficult to do otherwise.

A typical example of use is

failure := &Failure { eval: func(dir *MockDirectoryWrapper) { ... } }
...
mock.failOn(failure.reset())

func (*Failure) SetDoFail

func (f *Failure) SetDoFail()

type Handle

type Handle int

type MockDirectoryWrapper

type MockDirectoryWrapper struct {
	*BaseDirectoryWrapperImpl
	sync.Locker // simulate Java's synchronized keyword
	// contains filtered or unexported fields
}

This is a Directory wrapper that adds methods intended to be used only by unit tests. It also adds a number of fatures useful for testing:

1. Instances created by newDirectory() are tracked to ensure they are closed by the test. 2. When a MockDirectoryWrapper is closed, it returns an error if it has any open files against it (with a stacktrace indicating where they were opened from) 3. When a MockDirectoryWrapper is closed, it runs CheckIndex to test if the index was corrupted. 4. MockDirectoryWrapper simulates some "features" of Windows, such as refusing to write/delete to open files.

func NewMockDirectoryWrapper

func NewMockDirectoryWrapper(random *rand.Rand, delegate store.Directory) *MockDirectoryWrapper

func (*MockDirectoryWrapper) ClearLock

func (w *MockDirectoryWrapper) ClearLock(name string) error

func (*MockDirectoryWrapper) Close

func (w *MockDirectoryWrapper) Close() error

func (*MockDirectoryWrapper) Copy

func (w *MockDirectoryWrapper) Copy(to store.Directory, src string, dest string, context store.IOContext) error

func (*MockDirectoryWrapper) Crash

func (w *MockDirectoryWrapper) Crash() error

Simulates a crash of OS or machine by overwriting unsynced files.

func (*MockDirectoryWrapper) CreateOutput

func (w *MockDirectoryWrapper) CreateOutput(name string, context store.IOContext) (store.IndexOutput, error)

func (*MockDirectoryWrapper) DeleteFile

func (w *MockDirectoryWrapper) DeleteFile(name string) error

func (*MockDirectoryWrapper) FileExists

func (w *MockDirectoryWrapper) FileExists(name string) bool

func (*MockDirectoryWrapper) FileLength

func (w *MockDirectoryWrapper) FileLength(name string) (int64, error)

func (*MockDirectoryWrapper) ListAll

func (w *MockDirectoryWrapper) ListAll() ([]string, error)

func (*MockDirectoryWrapper) LockFactory

func (w *MockDirectoryWrapper) LockFactory() store.LockFactory

func (*MockDirectoryWrapper) LockID

func (w *MockDirectoryWrapper) LockID() string

func (*MockDirectoryWrapper) MakeLock

func (w *MockDirectoryWrapper) MakeLock(name string) store.Lock

func (*MockDirectoryWrapper) OpenInput

func (w *MockDirectoryWrapper) OpenInput(name string, context store.IOContext) (ii store.IndexInput, err error)

func (*MockDirectoryWrapper) SetLockFactory

func (w *MockDirectoryWrapper) SetLockFactory(lockFactory store.LockFactory)

func (*MockDirectoryWrapper) SetThrottling

func (mdw *MockDirectoryWrapper) SetThrottling(throttling Throttling)

func (*MockDirectoryWrapper) String

func (w *MockDirectoryWrapper) String() string

func (*MockDirectoryWrapper) Sync

func (w *MockDirectoryWrapper) Sync(names []string) error

type MockIndexInputWrapper

type MockIndexInputWrapper struct {
	*store.IndexInputImpl
	// contains filtered or unexported fields
}

Used by MockDirectoryWrapper to create an input stream that keeps track of when it's been closed.

func (*MockIndexInputWrapper) Clone

func (*MockIndexInputWrapper) Close

func (w *MockIndexInputWrapper) Close() (err error)

func (*MockIndexInputWrapper) FilePointer

func (w *MockIndexInputWrapper) FilePointer() int64

func (*MockIndexInputWrapper) Length

func (w *MockIndexInputWrapper) Length() int64

func (*MockIndexInputWrapper) ReadByte

func (w *MockIndexInputWrapper) ReadByte() (byte, error)

func (*MockIndexInputWrapper) ReadBytes

func (w *MockIndexInputWrapper) ReadBytes(buf []byte) error

func (*MockIndexInputWrapper) ReadInt

func (w *MockIndexInputWrapper) ReadInt() (int32, error)

func (*MockIndexInputWrapper) ReadLong

func (w *MockIndexInputWrapper) ReadLong() (int64, error)

func (*MockIndexInputWrapper) ReadShort

func (w *MockIndexInputWrapper) ReadShort() (int16, error)

func (*MockIndexInputWrapper) ReadString

func (w *MockIndexInputWrapper) ReadString() (string, error)

func (*MockIndexInputWrapper) ReadStringStringMap

func (w *MockIndexInputWrapper) ReadStringStringMap() (map[string]string, error)

func (*MockIndexInputWrapper) ReadVInt

func (w *MockIndexInputWrapper) ReadVInt() (int32, error)

func (*MockIndexInputWrapper) ReadVLong

func (w *MockIndexInputWrapper) ReadVLong() (int64, error)

func (*MockIndexInputWrapper) Seek

func (w *MockIndexInputWrapper) Seek(pos int64) error

func (*MockIndexInputWrapper) String

func (w *MockIndexInputWrapper) String() string

type MockIndexOutputWrapper

type MockIndexOutputWrapper struct {
	*store.IndexOutputImpl
	// contains filtered or unexported fields
}

Used by MockRAMDirectory to create an output stream that will throw an error on fake disk full, track max disk space actually used, and maybe throw random IO errors.

func (*MockIndexOutputWrapper) Close

func (w *MockIndexOutputWrapper) Close() (err error)

func (*MockIndexOutputWrapper) CopyBytes

func (w *MockIndexOutputWrapper) CopyBytes(input util.DataInput, numBytes int64) error

func (*MockIndexOutputWrapper) FilePointer

func (w *MockIndexOutputWrapper) FilePointer() int64

func (*MockIndexOutputWrapper) Flush

func (w *MockIndexOutputWrapper) Flush() error

func (*MockIndexOutputWrapper) Length

func (w *MockIndexOutputWrapper) Length() (int64, error)

func (*MockIndexOutputWrapper) String

func (w *MockIndexOutputWrapper) String() string

func (*MockIndexOutputWrapper) WriteByte

func (w *MockIndexOutputWrapper) WriteByte(b byte) error

func (*MockIndexOutputWrapper) WriteBytes

func (w *MockIndexOutputWrapper) WriteBytes(buf []byte) error

type MockLock

type MockLock struct {
	*store.LockImpl
	// contains filtered or unexported fields
}

func (*MockLock) Close

func (lock *MockLock) Close() error

func (*MockLock) IsLocked

func (lock *MockLock) IsLocked() bool

func (*MockLock) Obtain

func (lock *MockLock) Obtain() (ok bool, err error)

type MockLockFactoryWrapper

type MockLockFactoryWrapper struct {
	store.LockFactory
	// contains filtered or unexported fields
}

Used by MockDirectoryWrapper to wrap another factory and track open locks.

func (*MockLockFactoryWrapper) Clear

func (w *MockLockFactoryWrapper) Clear(lockName string) error

func (*MockLockFactoryWrapper) Make

func (w *MockLockFactoryWrapper) Make(lockName string) store.Lock

func (*MockLockFactoryWrapper) String

func (w *MockLockFactoryWrapper) String() string

type NullInfoStream

type NullInfoStream int

Prints nothing. Just to make sure tests pass w/ and w/o enabled InfoStream without actually making noise.

func (NullInfoStream) Clone

func (is NullInfoStream) Clone() util.InfoStream

func (NullInfoStream) Close

func (is NullInfoStream) Close() error

func (NullInfoStream) IsEnabled

func (is NullInfoStream) IsEnabled(component string) bool

func (NullInfoStream) Message

func (is NullInfoStream) Message(component, message string, args ...interface{})

type T

type T struct {
	// contains filtered or unexported fields
}

func (*T) Assert

func (c *T) Assert(ok bool)

func (*T) Assert2

func (c *T) Assert2(ok bool, msg string, args ...interface{})

func (*T) Error

func (c *T) Error(args ...interface{})

type TestRule

type TestRule interface {
	Apply(t *testing.T, f func(t *T)) func(t *T)
}

Mimic JUnit's TestRule

type TestRuleSetupAndRestoreClassEnv

type TestRuleSetupAndRestoreClassEnv struct {
	// contains filtered or unexported fields
}

Setup and restore suite-level environment (fine grained junk that doesn't fit anywhere else)

func (*TestRuleSetupAndRestoreClassEnv) After

func (rule *TestRuleSetupAndRestoreClassEnv) After() error

func (*TestRuleSetupAndRestoreClassEnv) Before

func (rule *TestRuleSetupAndRestoreClassEnv) Before() error

type ThreadNameFixingPrintStreamInfoStream

type ThreadNameFixingPrintStreamInfoStream struct {
	*util.PrintStreamInfoStream
}

func (*ThreadNameFixingPrintStreamInfoStream) Message

func (is *ThreadNameFixingPrintStreamInfoStream) Message(component, message string, args ...interface{})

type Throttling

type Throttling int

Controlling hard disk throttling Set via setThrottling() WARNING: can make tests very slow.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL