• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang hist.Eventstore类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/robertreppel/hist.Eventstore的典型用法代码示例。如果您正苦于以下问题:Golang Eventstore类的具体用法?Golang Eventstore怎么用?Golang Eventstore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Eventstore类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestStoringNewEvent

func TestStoringNewEvent(t *testing.T) {
	Convey("Given an event store", t, func() {
		dataStoreDirectory := "/tmp/hist-test-filestore-data"
		var eventStore hist.Eventstore
		var err error
		eventStore, err = FileStore(dataStoreDirectory)
		if err != nil {
			panic(err)
		}
		Convey("and an event which doesn't exist yet", func() {
			aggregateType := "TestSaveEventAggregate"
			id, _ := uuid.NewV4()
			aggregateID := id.String()
			data := []byte("Here's a test event.")
			Convey("when save event is called", func() {
				eventStore.Save(aggregateType, aggregateID, "EventType", data)
				Convey("then an aggregate  with the event exists.", func() {
					events, err := eventStore.Get(aggregateType, aggregateID)
					if err != nil {
						panic(err)
					}
					So(len(events) > 0, ShouldBeTrue)
				})
			})
		})
	})
}
开发者ID:robertreppel,项目名称:hist,代码行数:27,代码来源:save_event_command_test.go


示例2: TestGettingMoreThanOneEvent

func TestGettingMoreThanOneEvent(t *testing.T) {
	Convey("Given an event store", t, func() {
		dataStoreDirectory := "/tmp/hist-filestore-test-data"
		var eventStore hist.Eventstore
		var err error
		eventStore, err = FileStore(dataStoreDirectory)
		if err != nil {
			panic(err)
		}
		Convey("and three events", func() {
			expectedAggregateType := "TestGetMoreThanOneEventAggregate"
			id, _ := uuid.NewV4()
			aggregateID := id.String()
			data := []byte("{\"ShipID\":\"Seagull\",\"Location\":\"At Sea\"}")
			eventStore.Save(expectedAggregateType, aggregateID, "EventType", data)

			data = []byte("Second \n event.")
			eventStore.Save(expectedAggregateType, aggregateID, "EventType", data)

			data = []byte("Third event.")
			eventStore.Save(expectedAggregateType, aggregateID, "EventType", data)

			Convey("when get events is called", func() {
				Convey("then an aggregate  with three events is returned.", func() {
					events, err := eventStore.Get(expectedAggregateType, aggregateID)
					if err != nil {
						panic(err)
					}
					So(len(events), ShouldEqual, 3)
				})
			})
		})
	})
}
开发者ID:robertreppel,项目名称:hist,代码行数:34,代码来源:get_events_command_test.go


示例3: updatePortsOfCallHistory

func updatePortsOfCallHistory(shipName string, changes []interface{}) {
	var store hist.Eventstore
	var err error
	if useDynamo {
		store, err = dynamostore.DynamoStore(eventstoreTable, region, endpoint)
		failIf(err)
	} else {
		store, err = filestore.FileStore(dataStoreDirectory)
		failIf(err)
	}
	for _, event := range changes {
		jsonEvent, err := json.Marshal(event)
		failIf(err)
		store.Save("Ship", shipName, reflect.TypeOf(event).String(), []byte(jsonEvent))
	}
}
开发者ID:robertreppel,项目名称:hist,代码行数:16,代码来源:main.go


示例4: TestSavingToMissingDataDirectory

func TestSavingToMissingDataDirectory(t *testing.T) {
	Convey("Given an event store with a data directory that doesn't exist", t, func() {
		dataStoreDirectory := "/tmp/hist-filestore-test-saving-missing-directory"
		var eventStore hist.Eventstore
		var err error
		eventStore, err = FileStore(dataStoreDirectory)
		if err != nil {
			panic(err)
		}
		deleteAllData(dataStoreDirectory)
		Convey("saving an event should not succeed", func() {
			err = eventStore.Save("SomeAggregate", "12356", "EventType", []byte("event data."))
			So(err, ShouldNotBeNil)
			So(err.Error(), ShouldEqual, "No data directory")
		})
	})
}
开发者ID:robertreppel,项目名称:hist,代码行数:17,代码来源:save_event_command_test.go


示例5: TestMissingDataDirectory

func TestMissingDataDirectory(t *testing.T) {
	Convey("Given an event store", t, func() {
		dataStoreDirectory := "/tmp/hist-filestore-test-missing-datadirectory"
		var store hist.Eventstore
		var err error
		store, err = FileStore(dataStoreDirectory)
		if err != nil {
			panic(err)
		}
		deleteAllData(dataStoreDirectory)
		Convey("when I get an aggregate which doesn't exist", func() {
			_, err := store.Get("UnknownAggregate", "12345")
			Convey("an error should occur.", func() {
				So(err.Error(), ShouldEqual, "Missing data directory")
			})
		})
	})
}
开发者ID:robertreppel,项目名称:hist,代码行数:18,代码来源:get_events_command_test.go


示例6: TestGettingAggregateWhichDoesntExist

func TestGettingAggregateWhichDoesntExist(t *testing.T) {
	Convey("Given an event store", t, func() {
		dataStoreDirectory := "/tmp/hist-filestore-test-data"
		var store hist.Eventstore
		var err error
		store, err = FileStore(dataStoreDirectory)
		if err != nil {
			panic(err)
		}
		Convey("when I get an aggregate which doesn't exist", func() {
			events, err := store.Get("UnknownAggregate", "12345")
			if err != nil {
				panic(err)
			}
			Convey("the returned list of events should be empty.", func() {
				So(events, ShouldBeEmpty)
			})
		})
	})
}
开发者ID:robertreppel,项目名称:hist,代码行数:20,代码来源:get_events_command_test.go


示例7: getPortsOfCallHistory

func getPortsOfCallHistory(shipName string) []interface{} {
	var store hist.Eventstore
	var err error
	if useDynamo {
		store, err = dynamostore.DynamoStore(eventstoreTable, region, endpoint)
		failIf(err)
	} else {
		store, err = filestore.FileStore(dataStoreDirectory)
		failIf(err)
	}

	eventHistory, err := store.Get(shipAggregateType, shipName)
	failIf(err)

	var events []interface{}
	for _, item := range eventHistory {
		if item.Type == "ship.Registered" {
			var event ship.Registered
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
		if item.Type == "ship.Arrived" {
			var event ship.Arrived
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
		if item.Type == "ship.Departed" {
			var event ship.Departed
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
	}
	return events
}
开发者ID:robertreppel,项目名称:hist,代码行数:37,代码来源:main.go


示例8: TestGettingOneEvent

func TestGettingOneEvent(t *testing.T) {
	Convey("Given an event store", t, func() {
		dataStoreDirectory := "/tmp/hist-test-filestore-data"
		var eventStore hist.Eventstore
		var err error
		eventStore, err = FileStore(dataStoreDirectory)
		if err != nil {
			panic(err)
		}
		Convey("and an event", func() {
			expectedAggregateType := "TestGetEventAggregate"
			expectedEventType := "EventType"
			expectedEventData := "An event to get."
			id, _ := uuid.NewV4()
			aggregateID := id.String()
			data := []byte(expectedEventData)
			eventStore.Save(expectedAggregateType, aggregateID, expectedEventType, data)
			Convey("when get events is called", func() {
				Convey("then an aggregate  with the event is returned.", func() {
					events, err := eventStore.Get(expectedAggregateType, aggregateID)
					if err != nil {
						panic(err)
					}
					So(len(events), ShouldEqual, 1)
					event := events[0]
					Convey("and the type of the event is correct.", func() {
						So(event.Type, ShouldEqual, expectedEventType)
					})
					Convey("and the event data returned are correct.", func() {
						So(string(event.Data), ShouldEqual, expectedEventData)
					})
				})
			})
		})
	})
}
开发者ID:robertreppel,项目名称:hist,代码行数:36,代码来源:get_events_command_test.go


示例9: TestMandatoryParameters

func TestMandatoryParameters(t *testing.T) {
	dataStoreDirectory := "/tmp/hist-test-filestore-data"
	var eventStore hist.Eventstore
	var err error
	eventStore, err = FileStore(dataStoreDirectory)
	if err != nil {
		panic(err)
	}
	Convey("When saving an event without an aggregate type", t, func() {
		err = eventStore.Save("", "id", "EventType", []byte("Event data."))
		Convey("then an error occurs.", func() {
			So(err.Error(), ShouldEqual, "aggregateType cannot be blank")
		})
	})
	Convey("When saving an event without an aggregate id", t, func() {
		err = eventStore.Save("SomeAggregate", "", "EventType", []byte("Event data."))
		Convey("then an error occurs.", func() {
			So(err.Error(), ShouldEqual, "aggregateID cannot be blank")
		})
	})
	Convey("When saving an event without an event type", t, func() {
		err = eventStore.Save("SomeAggregate", "1234", "", []byte("Event data."))
		Convey("then an error occurs.", func() {
			So(err.Error(), ShouldEqual, "eventType cannot be blank")
		})
	})
	Convey("When saving an event without any data", t, func() {
		aggregateType := "GravelAggregate"
		id, _ := uuid.NewV4()
		aggregateID := id.String()
		var data []byte
		err = eventStore.Save(aggregateType, aggregateID, "EventType", data)
		Convey("then an error occurs.", func() {
			So(err, ShouldNotBeNil)
		})
	})
}
开发者ID:robertreppel,项目名称:hist,代码行数:37,代码来源:save_event_command_test.go



注:本文中的github.com/robertreppel/hist.Eventstore类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang config.ReadDefault函数代码示例发布时间:2022-05-28
下一篇:
Golang underscore.Disable函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap