Exemple #1
0
// Initializes an in-memory store and generates n transactions each with m
// randomly generated facts that belong to one of the specified domains.
func randMultidomainStorage(domains []string, n, m int) storage.Engine {
	engine, _ := origins.Init("memory", nil)

	for i := 0; i < m; i++ {
		tx, _ := transactor.New(engine, transactor.Options{
			AllowDuplicates: true,
		})

		gen := testutil.NewMultidomainGenerator(domains, tx.ID, n)

		origins.Copy(gen, tx)
		tx.Commit()
	}

	return engine
}
Exemple #2
0
// Initializes an in-memory store and generates n transactions each with m
// facts randomly generated from the same dictionary of possible E, A, V values.
// Varying the size of the dictionary relative to the size of the store
// allows to guarantee repeating facts.
func randStorageWRepeats(domain string, n, m, eLen, aLen, vLen int) storage.Engine {
	engine, _ := origins.Init("memory", nil)

	dictionary := testutil.NewEAVDictionary(eLen, aLen, vLen)

	for i := 0; i < m; i++ {
		tx, _ := transactor.New(engine, transactor.Options{
			AllowDuplicates: true,
		})

		gen := testutil.NewDictionaryBasedGenerator(dictionary, domain, tx.ID, n)

		origins.Copy(gen, tx)
		tx.Commit()
	}

	return engine
}
Exemple #3
0
func setup() storage.Engine {
	engine, _ := origins.Init("memory", nil)

	data, _ := testutil.Asset("assets/origins.csv")

	iter := origins.NewCSVReader(bytes.NewBuffer(data))

	tx, _ := transactor.New(engine, transactor.Options{})

	// Write the facts.
	if _, err := origins.Copy(iter, tx); err != nil {
		panic(err)
	}

	tx.Commit()

	return engine
}
Exemple #4
0
	Short: "Transacts facts into storage.",

	Long: `transact reads facts from stdin or from one or more paths specified paths.`,

	Run: func(cmd *cobra.Command, args []string) {
		bindStorageFlags(cmd.Flags())

		engine := initStorage()

		format := viper.GetString("transact_format")
		compression := viper.GetString("transact_compression")
		domain := viper.GetString("transact_domain")
		fake := viper.GetBool("transact_fake")

		tx, err := transactor.New(engine, transactor.Options{
			DefaultDomain: domain,
		})

		if err != nil {
			logrus.Fatal("transact: error starting transaction:", err)
		}

		// Register handler to catch interrupt (ctrl+c). The response
		// cancels the transaction. A panic recovery is used since facts
		// may still be sent on the stream after the channel is closed.
		// TODO: improve the cleanup handling.
		sig := make(chan os.Signal, 1)
		signal.Notify(sig, os.Interrupt, syscall.SIGTERM)

		go func() {
			<-sig