2015-08-25 20:52:42 +02:00
|
|
|
|
// Copyright (c) 2015 Couchbase, Inc.
|
|
|
|
|
// 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 firestorm
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"reflect"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2015-09-10 14:01:11 +02:00
|
|
|
|
"github.com/blevesearch/bleve/analysis/analyzers/standard_analyzer"
|
2015-08-25 20:52:42 +02:00
|
|
|
|
"github.com/blevesearch/bleve/document"
|
|
|
|
|
"github.com/blevesearch/bleve/index"
|
2015-10-28 16:26:01 +01:00
|
|
|
|
"github.com/blevesearch/bleve/index/store/gtreap"
|
2015-09-10 14:01:11 +02:00
|
|
|
|
"github.com/blevesearch/bleve/index/store/null"
|
|
|
|
|
"github.com/blevesearch/bleve/registry"
|
2015-08-25 20:52:42 +02:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestAnalysis(t *testing.T) {
|
|
|
|
|
|
2015-10-28 16:26:01 +01:00
|
|
|
|
aq := index.NewAnalysisQueue(1)
|
|
|
|
|
f, err := NewFirestorm(gtreap.Name, nil, aq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = f.Open()
|
2015-08-25 20:52:42 +02:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rows := []index.IndexRow{
|
|
|
|
|
NewFieldRow(0, IDFieldName),
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-28 16:26:01 +01:00
|
|
|
|
kvwriter, err := f.(*Firestorm).store.Writer()
|
2015-08-25 20:52:42 +02:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, row := range rows {
|
2015-10-28 16:26:01 +01:00
|
|
|
|
wb := kvwriter.NewBatch()
|
|
|
|
|
wb.Set(row.Key(), row.Value())
|
|
|
|
|
err := kvwriter.ExecuteBatch(wb)
|
2015-08-25 20:52:42 +02:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-28 16:26:01 +01:00
|
|
|
|
err = kvwriter.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kvreader, err := f.(*Firestorm).store.Reader()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2015-08-25 20:52:42 +02:00
|
|
|
|
// warmup to load field cache and set maxRead correctly
|
2015-11-24 20:32:33 +01:00
|
|
|
|
err = f.(*Firestorm).warmup(kvreader)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2015-08-25 20:52:42 +02:00
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
d *document.Document
|
|
|
|
|
r *index.AnalysisResult
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
d: document.NewDocument("a").
|
|
|
|
|
AddField(
|
2016-01-14 00:11:50 +01:00
|
|
|
|
document.NewTextFieldWithIndexingOptions("name", nil, []byte("test"), document.IndexField|document.StoreField|document.IncludeTermVectors)),
|
2015-08-25 20:52:42 +02:00
|
|
|
|
r: &index.AnalysisResult{
|
|
|
|
|
DocID: "a",
|
|
|
|
|
Rows: []index.IndexRow{
|
|
|
|
|
NewTermFreqRow(0, nil, []byte("a"), 1, 0, 0.0, nil),
|
2016-01-01 03:13:54 +01:00
|
|
|
|
NewFieldRow(1, "name"),
|
2015-08-25 20:52:42 +02:00
|
|
|
|
NewStoredRow([]byte("a"), 1, 1, nil, []byte("ttest")),
|
2015-12-21 20:59:32 +01:00
|
|
|
|
NewTermFreqRow(1, []byte("test"), []byte("a"), 1, 1, 1.0, []*TermVector{NewTermVector(1, 1, 0, 4, nil)}),
|
2015-08-25 20:52:42 +02:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
test.d.Number = 1
|
|
|
|
|
actual := f.Analyze(test.d)
|
|
|
|
|
if !reflect.DeepEqual(actual, test.r) {
|
|
|
|
|
t.Errorf("expected: %v got %v", test.r, actual)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-28 16:26:01 +01:00
|
|
|
|
err = kvreader.Close()
|
2015-08-25 20:52:42 +02:00
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-10 14:01:11 +02:00
|
|
|
|
|
2016-01-19 20:21:48 +01:00
|
|
|
|
func TestAnalysisBug328(t *testing.T) {
|
|
|
|
|
cache := registry.NewCache()
|
|
|
|
|
analyzer, err := cache.AnalyzerNamed(standard_analyzer.Name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
analysisQueue := index.NewAnalysisQueue(1)
|
|
|
|
|
idx, err := NewFirestorm(gtreap.Name, nil, analysisQueue)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d := document.NewDocument("1")
|
|
|
|
|
f := document.NewTextFieldCustom("title", nil, []byte("bleve"), document.IndexField|document.IncludeTermVectors, analyzer)
|
|
|
|
|
d.AddField(f)
|
|
|
|
|
f = document.NewTextFieldCustom("body", nil, []byte("bleve"), document.IndexField|document.IncludeTermVectors, analyzer)
|
|
|
|
|
d.AddField(f)
|
|
|
|
|
cf := document.NewCompositeFieldWithIndexingOptions("_all", true, []string{}, []string{}, document.IndexField|document.IncludeTermVectors)
|
|
|
|
|
d.AddField(cf)
|
|
|
|
|
|
|
|
|
|
rv := idx.Analyze(d)
|
|
|
|
|
fieldIndexes := make(map[uint16]string)
|
|
|
|
|
for _, row := range rv.Rows {
|
|
|
|
|
if row, ok := row.(*FieldRow); ok {
|
|
|
|
|
fieldIndexes[row.index] = row.Name()
|
|
|
|
|
}
|
|
|
|
|
if row, ok := row.(*TermFreqRow); ok && string(row.term) == "bleve" {
|
|
|
|
|
for _, vec := range row.Vectors() {
|
|
|
|
|
if vec.GetField() != uint32(row.field) {
|
|
|
|
|
if fieldIndexes[row.field] != "_all" {
|
|
|
|
|
t.Errorf("row named %s field %d - vector field %d", fieldIndexes[row.field], row.field, vec.GetField())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 14:01:11 +02:00
|
|
|
|
func BenchmarkAnalyze(b *testing.B) {
|
|
|
|
|
|
|
|
|
|
cache := registry.NewCache()
|
|
|
|
|
analyzer, err := cache.AnalyzerNamed(standard_analyzer.Name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
b.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-28 16:26:01 +01:00
|
|
|
|
analysisQueue := index.NewAnalysisQueue(1)
|
|
|
|
|
idx, err := NewFirestorm(null.Name, nil, analysisQueue)
|
2015-09-10 14:01:11 +02:00
|
|
|
|
if err != nil {
|
|
|
|
|
b.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d := document.NewDocument("1")
|
|
|
|
|
f := document.NewTextFieldWithAnalyzer("desc", nil, bleveWikiArticle1K, analyzer)
|
|
|
|
|
d.AddField(f)
|
|
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
rv := idx.Analyze(d)
|
|
|
|
|
if len(rv.Rows) < 92 || len(rv.Rows) > 93 {
|
|
|
|
|
b.Fatalf("expected 512-13 rows, got %d", len(rv.Rows))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bleveWikiArticle1K = []byte(`Boiling liquid expanding vapor explosion
|
|
|
|
|
From Wikipedia, the free encyclopedia
|
|
|
|
|
See also: Boiler explosion and Steam explosion
|
|
|
|
|
|
|
|
|
|
Flames subsequent to a flammable liquid BLEVE from a tanker. BLEVEs do not necessarily involve fire.
|
|
|
|
|
|
|
|
|
|
This article's tone or style may not reflect the encyclopedic tone used on Wikipedia. See Wikipedia's guide to writing better articles for suggestions. (July 2013)
|
|
|
|
|
A boiling liquid expanding vapor explosion (BLEVE, /ˈblɛviː/ blev-ee) is an explosion caused by the rupture of a vessel containing a pressurized liquid above its boiling point.[1]
|
|
|
|
|
Contents [hide]
|
|
|
|
|
1 Mechanism
|
|
|
|
|
1.1 Water example
|
|
|
|
|
1.2 BLEVEs without chemical reactions
|
|
|
|
|
2 Fires
|
|
|
|
|
3 Incidents
|
|
|
|
|
4 Safety measures
|
|
|
|
|
5 See also
|
|
|
|
|
6 References
|
|
|
|
|
7 External links
|
|
|
|
|
Mechanism[edit]
|
|
|
|
|
|
|
|
|
|
This section needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (July 2013)
|
|
|
|
|
There are three characteristics of liquids which are relevant to the discussion of a BLEVE:`)
|