Ejemplo n.º 1
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)
}
Ejemplo n.º 2
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)
}
Ejemplo n.º 3
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)
}