Expect(err).ToNot(HaveOccurred())
		URL, session = startTalaria(tmpDir)
		client = startClient(URL)
	})

	AfterEach(func() {
		session.Kill()
		session.Wait("10s", "100ms")

		Expect(os.RemoveAll(tmpDir)).To(Succeed())
		client.Close()
	})

	It("Writes and reads from a single file", func(done Done) {
		defer close(done)
		fileId, err := client.FetchFile("some-file")
		Expect(err).ToNot(HaveOccurred())
		for i := byte(0); i < 100; i++ {
			_, err = client.WriteToFile(fileId, []byte{i})
			Expect(err).ToNot(HaveOccurred())
		}

		for i := 0; i < 100; i++ {
			data, err := client.ReadFromFile(fileId)
			Expect(err).ToNot(HaveOccurred())
			Expect(data).To(HaveLen(1))
			Expect(data[0]).To(BeEquivalentTo(i))
		}
	}, 5)

	It("Writes and reads from a single file at the same time", func(done Done) {
Ejemplo n.º 2
0
	Context("FetchFile", func() {
		It("round robins the brokers while fetching new files", func(done Done) {
			defer close(done)

			for _, server := range mockServers {
				server.serverCh <- buildFileLocation(1)
			}

			var wg sync.WaitGroup
			defer wg.Wait()
			wg.Add(len(mockServers))
			for i := range mockServers {
				go func(iter int) {
					defer GinkgoRecover()
					defer wg.Done()
					_, err := client.FetchFile(fmt.Sprintf("some-file-%d", iter))
					Expect(err).ToNot(HaveOccurred())
				}(i)
			}

			for i, server := range mockServers {
				var msg *messages.Client
				Eventually(server.clientCh).Should(Receive(&msg))
				Expect(msg.GetMessageType()).To(Equal(messages.Client_FetchFile))
				Expect(msg.GetFetchFile().GetName()).To(Equal(fmt.Sprintf("some-file-%d", i)))
			}
		}, 5)

		It("re-fetches a file if it is redirected", func(done Done) {
			defer close(done)
			mockServers[0].serverCh <- buildRemoteFileLocation(1, servers[1].URL)