예제 #1
0
func TestSendFail(t *testing.T) {
	inBuffer := bytes.NewBuffer(nil)
	feedConf(inBuffer, t)

	outBuffer := bytes.NewBuffer(nil)

	input := stormenc.NewJsonObjectInput(inBuffer)
	output := stormenc.NewJsonObjectOutput(outBuffer)
	boltConn := stormcore.NewBoltConn(input, output, true)
	boltConn.Connect()

	var ids []string
	for i := 0; i < 1000; i++ {
		id := fmt.Sprintf("%d", rand.Int63())
		ids = append(ids, id)

		boltConn.SendFail(id)
	}
	output.Flush()

	expect(fmt.Sprintf(`{"pid":%d}`, os.Getpid()), outBuffer, t)
	expect("end", outBuffer, t)

	for i := 0; i < 1000; i++ {
		expect(fmt.Sprintf(`{"command":"fail","id":"%s"}`, ids[i]), outBuffer, t)
		expect("end", outBuffer, t)
	}

	checkPidFile(t)
}
예제 #2
0
func TestInit(t *testing.T) {
	inBuffer := bytes.NewBuffer(nil)
	feedConf(inBuffer, t)

	outBuffer := bytes.NewBuffer(nil)

	input := stormenc.NewJsonObjectInput(inBuffer)
	output := stormenc.NewJsonObjectOutput(outBuffer)
	boltConn := stormcore.NewBoltConn(input, output, true)
	boltConn.Connect()

	expectPid(outBuffer, t)

	// Check whether the pid file was created
	checkPidFile(t)
}
예제 #3
0
func main() {
	// Logging is done to an output file, since stdout and stderr are captured
	fo, err := os.Create(fmt.Sprintf("output%d.txt", os.Getpid()))
	if err != nil {
		panic(err)
	}
	defer fo.Close()
	log.SetOutput(fo)
	//log.SetOutput(os.Stdout)

	// This section allows us to correctly log signals and system panics
	go handleSigTerm()
	defer func() {
		if r := recover(); r != nil {
			log.Panicf("Recovered panic: %v", r)
		}
	}()

	input := jsonencoding.NewJsonObjectInput(os.Stdin)
	output := jsonencoding.NewJsonObjectOutput(os.Stdout)
	boltConn := core.NewBoltConn(input, output, false)
	boltConn.Connect()

	for {
		var sentence string
		// We have to read Raw here, since the spout is not json encoding the tuple contents
		meta := &messages.BoltMsgMeta{}
		err := boltConn.ReadBoltMsg(meta, &sentence)
		if err != nil {
			panic(err)
		}

		if meta.GetStream() == "__heartbeat" {
			boltConn.SendSync()
			continue
		}

		emitWords(sentence, meta.Id, boltConn)
		boltConn.SendAck(meta.Id)
	}
}
예제 #4
0
func TestReadTuple(t *testing.T) {
	buffer := bytes.NewBuffer(nil)

	feedReadBoltMsg(buffer, t)

	input := stormenc.NewJsonObjectInput(buffer)
	output := stormenc.NewJsonObjectOutput(os.Stdout)
	boltConn := stormcore.NewBoltConn(input, output, true)
	boltConn.Connect()

	var msg string
	for i := 0; i < 6; i++ {
		meta := &messages.BoltMsgMeta{}
		err := boltConn.ReadBoltMsg(meta, &msg)
		checkErr(err, t)
		msgCheck(msg, contents[i], t)
		metaTest(meta, i, t)
	}

	checkPidFile(t)
}
예제 #5
0
func testBoltEmit(taskIdsList [][]int32, inBuffer io.Reader, t *testing.T) {
	outBuffer := bytes.NewBuffer(nil)
	input := stormenc.NewJsonObjectInput(inBuffer)
	output := stormenc.NewJsonObjectOutput(outBuffer)
	boltConn := stormcore.NewBoltConn(input, output, true)
	boltConn.Connect()

	expectPid(outBuffer, t)

	var msg string
	for i := 0; i < 6; i++ {
		meta := &messages.BoltMsgMeta{}
		err := boltConn.ReadBoltMsg(meta, &msg)
		checkErr(err, t)
		msgCheck(msg, contents[i], t)
		metaTest(meta, i, t)

		taskIds := boltConn.Emit([]string{}, "", fmt.Sprintf("Msg%d", i))
		output.Flush()

		// Expect task Ids
		if len(taskIds) != len(taskIdsList[i]) {
			t.Error("Task id list is not of expected length")
		}
		for j := 0; j < len(taskIdsList[i]); j++ {
			if taskIds[j] != taskIdsList[i][j] {
				t.Error("Returned task Ids do not match expected")
			}
		}

		// Expect emission
		expect(fmt.Sprintf(`{"command":"emit","tuple":["Msg%d"]}`, i), outBuffer, t)
		expect("end", outBuffer, t)
	}

	checkPidFile(t)
}