Example #1
0
// used by IndexWriterConfig
func newLiveIndexWriterConfig(analyzer analysis.Analyzer, matchVersion util.Version) *LiveIndexWriterConfig {
	assert(DefaultSimilarity != nil)
	assert(DefaultCodec != nil)
	return &LiveIndexWriterConfig{
		analyzer:                analyzer,
		matchVersion:            matchVersion,
		ramBufferSizeMB:         DEFAULT_RAM_BUFFER_SIZE_MB,
		maxBufferedDocs:         DEFAULT_MAX_BUFFERED_DOCS,
		maxBufferedDeleteTerms:  DEFAULT_MAX_BUFFERED_DELETE_TERMS,
		readerTermsIndexDivisor: DEFAULT_READER_TERMS_INDEX_DIVISOR,
		termIndexInterval:       DEFAULT_TERM_INDEX_INTERVAL, // TODO: this should be private to the codec, not settable here
		delPolicy:               DEFAULT_DELETION_POLICY,
		useCompoundFile:         DEFAULT_USE_COMPOUND_FILE_SYSTEM,
		openMode:                OPEN_MODE_CREATE_OR_APPEND,
		similarity:              DefaultSimilarity(),
		mergeScheduler:          NewConcurrentMergeScheduler(),
		writeLockTimeout:        WRITE_LOCK_TIMEOUT,
		indexingChain:           defaultIndexingChain,
		codec:                   DefaultCodec(),
		infoStream:              util.DefaultInfoStream(),
		mergePolicy:             NewTieredMergePolicy(),
		flushPolicy:             newFlushByRamOrCountsPolicy(),
		readerPooling:           DEFAULT_READER_POOLING,
		indexerThreadPool:       NewDocumentsWriterPerThreadPool(DEFAULT_MAX_THREAD_STATES),
		perRoutineHardLimitMB:   DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB,
	}
}
Example #2
0
func (rule *TestRuleSetupAndRestoreClassEnv) Before() error {
	// if verbose: print some debugging stuff about which codecs are loaded.
	if VERBOSE {
		for _, codec := range index.AvailableCodecs() {
			log.Printf("Loaded codec: '%v': %v", codec,
				reflect.TypeOf(index.LoadCodec(codec)))
		}

		for _, postingFormat := range index.AvailablePostingsFormats() {
			log.Printf("Loaded postingsFormat: '%v': %v", postingFormat,
				reflect.TypeOf(index.LoadPostingsFormat(postingFormat)))
		}
	}

	rule.savedInfoStream = util.DefaultInfoStream()
	random := Random()
	if INFOSTREAM {
		util.SetDefaultInfoStream(newThreadNameFixingPrintStreamInfoStream(os.Stdout))
	} else if random.Intn(2) == 0 {
		util.SetDefaultInfoStream(NewNullInfoStream())
	}

	rule.avoidCodecs = make(map[string]bool)
	if suppressedCodecs != "" {
		rule.avoidCodecs[suppressedCodecs] = true
	}

	PREFLEX_IMPERSONATION_IS_ACTIVE = false
	rule.savedCodec = index.DefaultCodec()
	randomVal := random.Intn(10)
	if "Lucene3x" == TEST_CODEC ||
		"random" == TEST_CODEC &&
			"random" == TEST_POSTINGSFORMAT &&
			"random" == TEST_DOCVALUESFORMAT &&
			randomVal == 3 &&
			!rule.shouldAvoidCodec("Lucene3x") { // preflex-only setup
		panic("not supported yet")
	} else if "Lucene40" == TEST_CODEC ||
		"random" == TEST_CODEC &&
			"random" == TEST_POSTINGSFORMAT &&
			randomVal == 0 &&
			!rule.shouldAvoidCodec("Lucene40") { // 4.0 setup
		panic("not supported yet")
	} else if "Lucene41" == TEST_CODEC ||
		"random" == TEST_CODEC &&
			"random" == TEST_POSTINGSFORMAT &&
			"random" == TEST_DOCVALUESFORMAT &&
			randomVal == 1 &&
			!rule.shouldAvoidCodec("Lucene41") {
		panic("not supported yet")
	} else if "Lucene42" == TEST_CODEC ||
		"random" == TEST_CODEC &&
			"random" == TEST_POSTINGSFORMAT &&
			"random" == TEST_DOCVALUESFORMAT &&
			randomVal == 2 &&
			!rule.shouldAvoidCodec("Lucene42") {
		panic("not supported yet")
	} else if "random" != TEST_POSTINGSFORMAT ||
		"random" != TEST_DOCVALUESFORMAT {
		// the user wired postings or DV: this is messy
		// refactor into RandomCodec...

		panic("not supported yet")
	} else if "SimpleText" == TEST_CODEC ||
		"random" == TEST_CODEC &&
			randomVal == 9 &&
			Rarely(random) &&
			!rule.shouldAvoidCodec("SimpleText") {
		panic("not supported yet")
	} else if "Appending" == TEST_CODEC ||
		"random" == TEST_CODEC &&
			randomVal == 8 &&
			!rule.shouldAvoidCodec("Appending") {
		panic("not supported yet")
	} else if "CheapBastard" == TEST_CODEC ||
		"random" == TEST_CODEC &&
			randomVal == 8 &&
			!rule.shouldAvoidCodec("CheapBastard") &&
			!rule.shouldAvoidCodec("Lucene41") {
		panic("not supported yet")
	} else if "Asserting" == TEST_CODEC ||
		"random" == TEST_CODEC &&
			randomVal == 6 &&
			!rule.shouldAvoidCodec("Asserting") {
		panic("not implemented yet")
	} else if "Compressing" == TEST_CODEC ||
		"random" == TEST_CODEC &&
			randomVal == 5 &&
			!rule.shouldAvoidCodec("Compressing") {
		panic("not supported yet")
	} else if "random" != TEST_CODEC {
		rule.codec = index.LoadCodec(TEST_CODEC)
	} else if "random" == TEST_POSTINGSFORMAT {
		panic("not supported yet")
	} else {
		assert(false)
	}
	log.Printf("Use codec: %v", rule.codec)
	index.DefaultCodec = func() index.Codec { return rule.codec }

	// Initialize locale/ timezone
	// testLocale := or(os.Getenv("tests.locale"), "random")
	// testTimeZon := or(os.Getenv("tests.timezone"), "random")

	// Always pick a random one for consistency (whether tests.locale
	// was specified or not)
	// Ian: it's not supported yet
	// rule.savedLocale := DefaultLocale()
	// if "random" == testLocale {
	// 	rule.locale = randomLocale(random)
	// } else {
	// 	rule.locale = localeForName(testLocale)
	// }
	// SetDefaultLocale(rule.locale)

	// SetDefaultTimeZone() will set user.timezone to the default
	// timezone of the user's locale. So store the original property
	// value and restore it at end.
	// rule.restoreProperties["user.timezone"] = os.Getenv("user.timezone")
	// rule.savedTimeZone = DefaultTimeZone()
	// if "random" == testTimeZone {
	// 	rule.timeZone = randomTimeZone(random)
	// } else {
	// 	rule.timeZone = TimeZone(testTimeZone)
	// }
	// SetDefaultTImeZone(rule.timeZone)

	if random.Intn(2) == 0 {
		rule.similarity = search.NewDefaultSimilarity()
	} else {
		rule.similarity = ts.NewRandomSimilarityProvider(random)
	}

	// Check codec restrictions once at class level.
	err := rule.checkCodecRestrictions(rule.codec)
	if err != nil {
		log.Printf("NOTE: %v Suppressed codecs: %v", err, rule.avoidCodecs)
	}
	return err
}