mirror of
https://github.com/minio/minio.git
synced 2025-03-03 07:10:07 -05:00
Updating iodine, now has global state.
This commit is contained in:
parent
31482659be
commit
abe49919ed
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -20,7 +20,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/minio-io/iodine",
|
"ImportPath": "github.com/minio-io/iodine",
|
||||||
"Rev": "d7c4850883ade19431e3808e9c712d3d3e69cdcc"
|
"Rev": "b279ca8ea714fabc969883a4d1612a4e93d01611"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "gopkg.in/check.v1",
|
"ImportPath": "gopkg.in/check.v1",
|
||||||
|
39
Godeps/_workspace/src/github.com/minio-io/iodine/iodine.go
generated
vendored
39
Godeps/_workspace/src/github.com/minio-io/iodine/iodine.go
generated
vendored
@ -23,6 +23,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error is the iodine error which contains a pointer to the original error
|
// Error is the iodine error which contains a pointer to the original error
|
||||||
@ -42,6 +43,35 @@ type StackEntry struct {
|
|||||||
Data map[string]string
|
Data map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var globalState = struct {
|
||||||
|
sync.RWMutex
|
||||||
|
m map[string]string
|
||||||
|
}{m: make(map[string]string)}
|
||||||
|
|
||||||
|
func SetGlobalState(key, value string) {
|
||||||
|
globalState.Lock()
|
||||||
|
globalState.m[key] = value
|
||||||
|
globalState.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func ClearGlobalState() {
|
||||||
|
globalState.Lock()
|
||||||
|
for k, _ := range globalState.m {
|
||||||
|
delete(globalState.m, k)
|
||||||
|
}
|
||||||
|
globalState.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetGlobalState() map[string]string {
|
||||||
|
result := make(map[string]string)
|
||||||
|
globalState.RLock()
|
||||||
|
for k, v := range globalState.m {
|
||||||
|
result[k] = v
|
||||||
|
}
|
||||||
|
globalState.RUnlock()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// Wrap an error, turning it into an iodine error.
|
// Wrap an error, turning it into an iodine error.
|
||||||
// Adds an initial stack trace.
|
// Adds an initial stack trace.
|
||||||
func New(err error, data map[string]string) *Error {
|
func New(err error, data map[string]string) *Error {
|
||||||
@ -63,18 +93,17 @@ func createStackEntry() StackEntry {
|
|||||||
Host: host,
|
Host: host,
|
||||||
File: file,
|
File: file,
|
||||||
Line: line,
|
Line: line,
|
||||||
Data: make(map[string]string),
|
Data: GetGlobalState(),
|
||||||
}
|
}
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annotate an error with a stack entry and returns itself
|
// Annotate an error with a stack entry and returns itself
|
||||||
func (err *Error) Annotate(info map[string]string) *Error {
|
func (err *Error) Annotate(info map[string]string) *Error {
|
||||||
data := make(map[string]string)
|
|
||||||
for k, v := range info {
|
|
||||||
data[k] = v
|
|
||||||
}
|
|
||||||
entry := createStackEntry()
|
entry := createStackEntry()
|
||||||
|
for k, v := range info {
|
||||||
|
entry.Data[k] = v
|
||||||
|
}
|
||||||
err.Stack = append(err.Stack, entry)
|
err.Stack = append(err.Stack, entry)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
52
Godeps/_workspace/src/github.com/minio-io/iodine/iodine_test.go
generated
vendored
52
Godeps/_workspace/src/github.com/minio-io/iodine/iodine_test.go
generated
vendored
@ -38,6 +38,54 @@ func TestIodine(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var prettyBuffer bytes.Buffer
|
var prettyBuffer bytes.Buffer
|
||||||
json.Indent(&prettyBuffer, jsonResult, "", " ")
|
json.Indent(&prettyBuffer, jsonResult, "", " ")
|
||||||
log.Println(string(prettyBuffer.Bytes()))
|
}
|
||||||
log.Println(iodineError.EmitHumanReadable())
|
|
||||||
|
func TestState(t *testing.T) {
|
||||||
|
SetGlobalState("hello", "world")
|
||||||
|
state := GetGlobalState()
|
||||||
|
if res, ok := state["hello"]; ok {
|
||||||
|
if res != "world" {
|
||||||
|
t.Error("global state not set: hello->world")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
ClearGlobalState()
|
||||||
|
if len(GetGlobalState()) != 0 {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
SetGlobalState("foo", "bar")
|
||||||
|
err := New(errors.New("a simple error"), nil)
|
||||||
|
if res, ok := err.Stack[0].Data["foo"]; ok {
|
||||||
|
if res != "bar" {
|
||||||
|
t.Error("global state not set: foo->bar")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
err.Annotate(map[string]string{"foo2": "bar2"})
|
||||||
|
if res, ok := err.Stack[0].Data["foo"]; ok {
|
||||||
|
if res != "bar" {
|
||||||
|
t.Error("annotate should not modify previous data entries")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Error("annotate should not remove previous data entries")
|
||||||
|
}
|
||||||
|
if res, ok := err.Stack[1].Data["foo"]; ok {
|
||||||
|
if res != "bar" {
|
||||||
|
t.Error("global state should set value properly in annotate")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Error("global state should set key properly in annotate")
|
||||||
|
}
|
||||||
|
if res, ok := err.Stack[1].Data["foo2"]; ok {
|
||||||
|
if res != "bar2" {
|
||||||
|
err.Annotate(nil)
|
||||||
|
t.Error("foo2 -> bar should be set")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err.Annotate(nil)
|
||||||
|
log.Println(err.EmitHumanReadable())
|
||||||
|
t.Error("foo2 should be set")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
2
Godeps/_workspace/src/gopkg.in/check.v1/benchmark_test.go
generated
vendored
2
Godeps/_workspace/src/gopkg.in/check.v1/benchmark_test.go
generated
vendored
@ -3,8 +3,8 @@
|
|||||||
package check_test
|
package check_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
. "gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var benchmarkS = Suite(&BenchmarkS{})
|
var benchmarkS = Suite(&BenchmarkS{})
|
||||||
|
15
Godeps/_workspace/src/gopkg.in/check.v1/printer_test.go
generated
vendored
15
Godeps/_workspace/src/gopkg.in/check.v1/printer_test.go
generated
vendored
@ -24,22 +24,27 @@ func printTestFunc() {
|
|||||||
println(3) // Comment3
|
println(3) // Comment3
|
||||||
}
|
}
|
||||||
switch 5 {
|
switch 5 {
|
||||||
case 6: println(6) // Comment6
|
case 6:
|
||||||
|
println(6) // Comment6
|
||||||
println(7)
|
println(7)
|
||||||
}
|
}
|
||||||
switch interface{}(9).(type) { // Comment9
|
switch interface{}(9).(type) { // Comment9
|
||||||
case int: println(10)
|
case int:
|
||||||
|
println(10)
|
||||||
println(11)
|
println(11)
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case <-(chan bool)(nil): println(14)
|
case <-(chan bool)(nil):
|
||||||
|
println(14)
|
||||||
println(15)
|
println(15)
|
||||||
default: println(16)
|
default:
|
||||||
|
println(16)
|
||||||
println(17)
|
println(17)
|
||||||
}
|
}
|
||||||
println(19,
|
println(19,
|
||||||
20)
|
20)
|
||||||
_ = func() { println(21)
|
_ = func() {
|
||||||
|
println(21)
|
||||||
println(22)
|
println(22)
|
||||||
}
|
}
|
||||||
println(24, func() {
|
println(24, func() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user