-
Notifications
You must be signed in to change notification settings - Fork 7
/
fragment_info_test.go
166 lines (126 loc) · 4.2 KB
/
fragment_info_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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package tiledb
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFragmentInfo(t *testing.T) {
// Create configuration
config, err := NewConfig()
require.NoError(t, err)
// Test context with config
context, err := NewContext(config)
require.NoError(t, err)
fragmentSize := testFragmentInfo(t, context)
assert.Equal(t, uint64(4290), fragmentSize)
}
func TestFragmentInfoEncryption(t *testing.T) {
encryption_key := "unittestunittestunittestunittest"
// Create configuration
config, err := NewConfig()
require.NoError(t, err)
err = config.Set("sm.encryption_type", TILEDB_AES_256_GCM.String())
require.NoError(t, err)
err = config.Set("sm.encryption_key", encryption_key)
require.NoError(t, err)
// Test context with config
context, err := NewContext(config)
require.NoError(t, err)
fragmentSize := testFragmentInfo(t, context)
assert.Equal(t, uint64(7601), fragmentSize)
}
func testFragmentInfo(t testing.TB, context *Context) uint64 {
// create temp group name
tmpArrayPath := t.TempDir()
// Create new array struct
array, err := NewArray(context, tmpArrayPath)
require.NoError(t, err)
assert.NotNil(t, array)
arraySchema := buildArraySchema(context, t)
// Create array on disk
require.NoError(t, array.Create(arraySchema))
// Get array URI
uri, err := array.URI()
require.NoError(t, err)
assert.Equal(t, "file://"+tmpArrayPath, uri)
// Close Array
require.NoError(t, array.Close())
array.Free()
// Create new fragment info struct
fI, err := NewFragmentInfo(context, uri)
require.NoError(t, err)
assert.NotNil(t, fI)
// Load fragment info
require.NoError(t, fI.Load())
num, err := fI.GetFragmentNum()
require.NoError(t, err)
assert.Equal(t, uint32(0), num)
writeToArray(t, context, tmpArrayPath)
// Load fragment info again
require.NoError(t, fI.Load())
num, err = fI.GetFragmentNum()
require.NoError(t, err)
assert.Equal(t, uint32(1), num)
fragmentURI, err := fI.GetFragmentURI(0)
require.NoError(t, err)
assert.NotEmpty(t, fragmentURI)
fragmentSize, err := fI.GetFragmentSize(0)
require.NoError(t, err)
isDense, err := fI.GetDense(0)
require.NoError(t, err)
assert.Equal(t, true, isDense)
isSparse, err := fI.GetSparse(0)
require.NoError(t, err)
assert.Equal(t, false, isSparse)
t1, t2, err := fI.GetTimestampRange(0)
require.NoError(t, err)
assert.Equal(t, t2, t1)
nonEmptyDomain, err := fI.GetNonEmptyDomainFromIndex(0, 0)
require.NoError(t, err)
assert.Equal(t, "dim1", nonEmptyDomain.DimensionName)
assert.Equal(t, []int8{1, 10}, nonEmptyDomain.Bounds)
nonEmptyDomain, err = fI.GetNonEmptyDomainFromName(0, "dim1")
require.NoError(t, err)
assert.Equal(t, "dim1", nonEmptyDomain.DimensionName)
assert.Equal(t, []int8{1, 10}, nonEmptyDomain.Bounds)
cellNum, err := fI.GetCellNum(0)
require.NoError(t, err)
assert.Equal(t, uint64(10), cellNum)
version, err := fI.GetVersion(0)
require.NoError(t, err)
assert.Greater(t, version, uint32(0))
hasConsolidatedMetadata, err := fI.HasConsolidatedMetadata(0)
require.NoError(t, err)
assert.Equal(t, false, hasConsolidatedMetadata)
unconsolidatedMetadataNum, err := fI.GetUnconsolidatedMetadataNum()
require.NoError(t, err)
assert.Equal(t, uint32(1), unconsolidatedMetadataNum)
toVacuumNum, err := fI.GetToVacuumNum()
require.NoError(t, err)
assert.Equal(t, uint32(0), toVacuumNum)
_, err = fI.GetToVacuumURI(0)
assert.Error(t, err)
fI.Free()
return fragmentSize
}
func writeToArray(t testing.TB, context *Context, tmpArrayPath string) {
// Prepare some data for the array
a1 := []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
a2 := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}
a2Off := []uint64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
// Create the query
array, err := NewArray(context, tmpArrayPath)
require.NoError(t, err)
require.NoError(t, array.Open(TILEDB_WRITE))
query, err := NewQuery(context, array)
require.NoError(t, err)
require.NoError(t, query.SetLayout(TILEDB_ROW_MAJOR))
_, err = query.SetDataBuffer("a1", a1)
require.NoError(t, err)
_, err = query.SetDataBuffer("a2", a2)
require.NoError(t, err)
_, err = query.SetOffsetsBuffer("a2", a2Off)
require.NoError(t, err)
require.NoError(t, query.Submit())
require.NoError(t, array.Close())
}