예제 #1
0
		AfterEach(func() {
			session.Kill()
			session.Wait("10s", "100ms")

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

		Measure("It should read and write to single file 1000 times in under a second", func(b Benchmarker) {
			runtime := b.Time("runtime", func() {
				fileId, err := client.FetchFile("some-file")
				Expect(err).ToNot(HaveOccurred())

				for i := 0; i < 1000; i++ {
					_, err = client.WriteToFile(fileId, []byte{byte(i)})
					Expect(err).ToNot(HaveOccurred())
				}

				for i := 0; i < 1000; i++ {
					data, err := client.ReadFromFile(fileId)
					Expect(err).ToNot(HaveOccurred())
					Expect(data[0]).To(Equal(byte(i)))
				}
			})
			Expect(runtime.Seconds()).To(BeNumerically("<", 1))
		}, 1)

	})

	Context("Multiple Brokers", func() {
	})

	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) {
		defer close(done)
		clientW := startClient(URL)
		clientR := startClient(URL)
예제 #3
0
			Expect(ffErr).ToNot(HaveOccurred())

			var msg *messages.Client
			Eventually(mockServers[1].clientCh).Should(Receive(&msg))
			Expect(msg.GetMessageType()).To(Equal(messages.Client_FetchFile))
			Expect(msg.GetFetchFile().GetName()).To(Equal("some-file-1"))

			var wg sync.WaitGroup
			defer wg.Wait()
			for i := 0; i < 10; i++ {
				wg.Add(1)
				go func() {
					defer GinkgoRecover()
					defer wg.Done()
					expectedData := []byte("some-data")
					_, err := client.WriteToFile(id, expectedData)
					Expect(err).ToNot(HaveOccurred())

					var msg *messages.Client
					Eventually(mockServers[1].clientCh).Should(Receive(&msg))
					Expect(msg.GetMessageType()).To(Equal(messages.Client_WriteToFile))
					Expect(msg.GetWriteToFile().GetData()).To(Equal(expectedData))
				}()
			}
		}, 5)

		Measure("Writes to a file 1000 times in under a second", func(b Benchmarker) {
			runtime := b.Time("runtime", func() {
				mockServers[0].serverCh <- buildFileLocation(1)
				count := 1000