Exemplo n.º 1
0
func TestOutputValueFile(t *testing.T) {
	if err := nodedb.Initialize(); err != nil {
		t.Fatalf("nodedb.Initialize() %s", err)
	}

	info, err := tools.NewFileSpaceInfo(nodedb.NodeDB)
	if err != nil {
		t.Fatalf("NewFileSpaceInfo( %s", err)
	}

	valueFile, err := NewOutputValueFile(info)
	if err != nil {
		t.Fatalf("NewOutputValueFile %s", err)
	}

	collectionID := uint32(42)
	segmentID := uint64(88)
	dataSize := 1024
	data := bytes.Repeat([]byte{'a'}, dataSize)

	if _, err := valueFile.Store(collectionID, segmentID, data); err != nil {
		t.Fatalf("valueFile.Store %s", err)
	}

	if valueFile.Size() != uint64(dataSize) {
		t.Fatalf("size mismatch: expecting %d, found %d", dataSize,
			valueFile.Size())
	}

	if err := valueFile.Close(); err != nil {
		t.Fatalf("valueFile.Close() %s", err)
	}
}
Exemplo n.º 2
0
func NewMessageHandler() chan<- types.Message {
	var nimbusioWriter writer.NimbusioWriter
	var replyChan chan<- *reply.ReplyMessage
	var err error

	messageChan := make(chan types.Message, messageChanCapacity)

	if err = nodedb.Initialize(); err != nil {
		fog.Critical("NewMessageHandler: nodedb.Initialize failed %s", err)
	}

	if nimbusioWriter, err = writer.NewNimbusioWriter(); err != nil {
		fog.Critical("NewMessageHandler: NewNimbusioWriter() failed %s", err)
	}

	replyChan = reply.NewReplyHandler()

	dispatchTable := map[string]messageHandler{
		"archive-key-entire":       handleArchiveKeyEntire,
		"archive-key-start":        handleArchiveKeyStart,
		"archive-key-next":         handleArchiveKeyNext,
		"archive-key-final":        handleArchiveKeyFinal,
		"archive-key-cancel":       handleArchiveKeyCancel,
		"destroy-key":              handleDestroyKey,
		"start-conjoined-archive":  handleStartConjoinedArchive,
		"abort-conjoined-archive":  handleAbortConjoinedArchive,
		"finish-conjoined-archive": handleFinishConjoinedArchive}

	go func() {
		for message := range messageChan {
			handler, ok := dispatchTable[message.Type]
			if !ok {
				fog.Error("Unknown message type %s %s",
					message.Type, message.Marshalled)
				continue
			}
			go handler(message, nimbusioWriter, replyChan)
		}
	}()

	return messageChan
}