示例#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 TestSendSync(t *testing.T) {
	inBuffer := bytes.NewBuffer(nil)
	feedConf(inBuffer, t)
	outBuffer := bytes.NewBuffer(nil)
	input := stormenc.NewJsonObjectInput(inBuffer)
	output := stormenc.NewJsonObjectOutput(outBuffer)
	spoutConn := stormcore.NewSpoutConn(input, output, true)
	spoutConn.Connect()

	expectPid(outBuffer, t)

	for i := 0; i < 6; i++ {
		spoutConn.SendSync()
		// Expect emission
		expect(`{"command":"sync"}`, outBuffer, t)
		expect("end", outBuffer, t)
	}

	checkPidFile(t)
}
示例#4
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)
	}
}
示例#5
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)
}
示例#6
0
func TestLog(t *testing.T) {
	inBuffer := bytes.NewBuffer(nil)
	feedConf(inBuffer, t)
	outBuffer := bytes.NewBuffer(nil)
	input := stormenc.NewJsonObjectInput(inBuffer)
	output := stormenc.NewJsonObjectOutput(outBuffer)
	spoutConn := stormcore.NewSpoutConn(input, output, true)
	spoutConn.Connect()

	expectPid(outBuffer, t)

	for i := 0; i < 6; i++ {
		msg := fmt.Sprintf("%d", rand.Int63())
		spoutConn.Log(msg)
		// Expect emission
		expect(fmt.Sprintf(`{"command":"log","msg":"%s"}`, msg), outBuffer, t)
		expect("end", outBuffer, t)
	}

	checkPidFile(t)
}
示例#7
0
func TestReadMsg(t *testing.T) {
	buffer := bytes.NewBuffer(nil)

	spoutMsgs := feedReadMsg(buffer, t)

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

	for i := 0; i < 6; i++ {
		command, id, err := spoutConn.ReadSpoutMsg()
		checkErr(err, t)
		if command != spoutMsgs[i].Command {
			t.Fatalf(fmt.Sprintf("Incorrect command received: expected: %s, received: %s", spoutMsgs[i].Command, command))
		}
		if id != spoutMsgs[i].Id {
			t.Fatalf(fmt.Sprintf("Incorrect id received: expected: %s, received: %s", spoutMsgs[i].Id, id))
		}
	}

	checkPidFile(t)
}
示例#8
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)
}