-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcontext_test.go
130 lines (109 loc) · 2.89 KB
/
context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package tiledb
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// ExampleNewContext example of creating a new context
func ExampleNewContext() {
// Create Context with default configuration:
context, err := NewContext(nil)
if err != nil {
// handle error
return
}
// Create a config and use it to create a new Context:
// (See ExampleConfig_Set for an example of setting config variables.)
config, err := NewConfig()
if err != nil {
// handle error
return
}
context, err = NewContext(config)
if err != nil {
// handle error
return
}
// Create a context directly from a configuration map:
context, err = NewContextFromMap(map[string]string{
"sm.memory_budget": "17179869184", // 16 GiB
"sm.memory_budget_var": "34359738368", // 32 GiB
})
if err != nil {
// handle error
return
}
stats, err := context.Stats()
if err != nil {
// Handle error
return
}
if len(stats) > 0 {
// Do something with stats
}
// Check if S3 is supported:
isS3Supported, err := context.IsSupportedFS(TILEDB_S3)
if err != nil {
// handle error
return
}
// Output: true
fmt.Println(isS3Supported)
}
// TestNewContext tests setting a new context
func TestNewContext(t *testing.T) {
context, err := NewContext(nil)
require.NoError(t, err)
// Test freeing c allocs
context.Free()
config, err := NewConfig()
require.NoError(t, err)
// Test context with config
context, err = NewContext(config)
require.NoError(t, err)
assert.NotNil(t, context)
}
// TestNewContext tests setting a new context
func TestCancelAllTasks(t *testing.T) {
config, err := NewConfig()
assert.Nil(t, err)
context, err := NewContext(config)
assert.Nil(t, err)
assert.NotNil(t, context)
// just call cancel with no tasks
assert.NoError(t, context.CancelAllTasks())
}
// TestGetContextConfig tests creating a new Context with config vars.
func TestGetContextConfig(t *testing.T) {
// Create a context with a non-default value:
context, err := NewContextFromMap(map[string]string{
"sm.memory_budget": "4294967296",
})
require.NoError(t, err)
config, err := context.Config()
require.NoError(t, err)
// Validate config has setting changed
val, err := config.Get("sm.memory_budget")
require.NoError(t, err)
assert.Equal(t, "4294967296", val)
}
// TestContextLastError tests retrieving the last error
func TestContextLastError(t *testing.T) {
context, err := NewContext(nil)
require.NoError(t, err)
ctxErr := context.LastError()
assert.Nil(t, ctxErr)
}
// TestContextIsFSSupported tests if we can detect filesystem support properly
func TestContextIsFSSupported(t *testing.T) {
context, err := NewContext(nil)
require.NoError(t, err)
_, ctxErr := context.IsSupportedFS(TILEDB_S3)
assert.Nil(t, ctxErr)
}
func TestContextSetTag(t *testing.T) {
context, err := NewContext(nil)
require.NoError(t, err)
require.NoError(t, context.SetTag("key", "value"))
}