Skip to content

Commit 70bb1f1

Browse files
committed
test passing with BlobEntry
1 parent d5d26e7 commit 70bb1f1

File tree

10 files changed

+80
-52
lines changed

10 files changed

+80
-52
lines changed

src/DataBlobs/DataBlobs.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ include("services/AbstractBlobEntries.jl")
1010
include("services/BlobEntry.jl")
1111
include("services/BlobStores.jl")
1212

13-
include("services/InMemoryStore.jl")
13+
# include("services/InMemoryStore.jl")
1414

1515

1616
export BlobEntry
1717

1818
export getBlob, addBlob!, updateBlob!, deleteBlob!, listBlobEntries
19-
export getBlobBlob, addBlob!, updateBlob!, deleteBlob!, listBlobs
20-
export copyStore
19+
export listBlobs
20+
export BlobEntry
21+
# export copyStore
2122

2223
export getId, getHash, getTimestamp

src/DataBlobs/entities/AbstractBlobEntries.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ getTimestamp(entry::AbstractBlobEntry) = entry.timestamp
1414
##==============================================================================
1515
## BlobStoreEntry
1616
##==============================================================================
17-
export BlobEntry
1817

1918
"""
2019
$(TYPEDEF)

src/DataBlobs/services/BlobEntry.jl

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

2-
function assertHash(de::AbstractBlobEntry, db; hashfunction = sha256)
3-
getHash(de) === nothing && @warn "Hey friends, how about some hashing?" && return true
2+
function assertHash(
3+
de::AbstractBlobEntry,
4+
db::AbstractVector{UInt8};
5+
hashfunction::Function = sha256
6+
)
7+
getHash(de) === nothing && @warn "Missing hash?" && return true
48
if hashfunction(db) == getHash(de)
59
return true #or nothing?
610
else
@@ -92,7 +96,7 @@ function deleteBlob! end
9296

9397

9498
function getBlob(dfg::AbstractDFG, entry::AbstractBlobEntry)
95-
error("$(typeof(dfg)) doesn't override 'getBlob'.")
99+
error("$(typeof(dfg)) doesn't override 'getBlob', with $(typeof(entry)).")
96100
end
97101

98102
function addBlob!(dfg::AbstractDFG, entry::AbstractBlobEntry, data::T) where T
@@ -115,6 +119,14 @@ end
115119
## DFG Blob CRUD
116120
##==============================================================================
117121

122+
# function getBlob(
123+
# dfg::AbstractDFG,
124+
# entry::BlobEntry;
125+
# checkhash::Bool=true,
126+
# )
127+
128+
# end
129+
118130
function getBlob(
119131
dfg::AbstractDFG,
120132
vlabel::Symbol,
@@ -128,7 +140,7 @@ function getBlob(
128140
de = _first(de_)
129141
db = getBlob(dfg, de)
130142

131-
checkhash && de.hash !== nothing && assertHash(de, db, hashfunction=hashfunction)
143+
checkhash && assertHash(de, db, hashfunction=hashfunction)
132144
return de=>db
133145
end
134146

@@ -140,12 +152,27 @@ function addBlob!(
140152
hashfunction = sha256,
141153
checkhash::Bool=true
142154
)
143-
checkhash && de.hash !== nothing && assertHash(entry, blob, hashfunction=hashfunction)
155+
checkhash && assertHash(entry, blob, hashfunction=hashfunction)
144156
de = addBlobEntry!(dfg, label, entry)
145157
db = addBlob!(dfg, de, blob)
146158
return de=>db
147159
end
148160

161+
function addBlob!(
162+
::Type{<:BlobEntry},
163+
dfg::AbstractDFG,
164+
label::Symbol,
165+
key::Symbol,
166+
blob::AbstractVector{UInt8},
167+
timestamp=now(localzone());
168+
id::UUID = uuid4(),
169+
hashfunction::Function = sha256
170+
)
171+
fde = BlobEntry(key, id, timestamp, blob)
172+
de = addBlobEntry!(dfg, label, fde)
173+
return de=>blob
174+
end
175+
149176
function updateBlob!(
150177
dfg::AbstractDFG,
151178
label::Symbol,
@@ -154,7 +181,7 @@ function updateBlob!(
154181
hashfunction = sha256,
155182
checkhash::Bool=true
156183
)
157-
checkhash && de.hash !== nothing && assertHash(entry, blob, hashfunction=hashfunction)
184+
checkhash && assertHash(entry, blob, hashfunction=hashfunction)
158185
de = updateBlobEntry!(dfg, label, entry)
159186
db = updateBlob!(dfg, de, blob)
160187
return de=>db

src/DataBlobs/services/BlobStores.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
##==============================================================================
44

55
function getBlob(dfg::AbstractDFG, entry::BlobEntry)
6-
@show entry
7-
@show "I'm here"
86
# cannot use entry.blobstore because the blob can be in any one of the blobstores
97
stores = getBlobStores(dfg)
108
for (k,store) in stores
@@ -98,7 +96,7 @@ end
9896

9997
function addBlob!(dfg::AbstractDFG, blobstore::AbstractBlobStore, label::Symbol, entry::AbstractBlobEntry, blob::Vector{UInt8}; hashfunction = sha256)
10098
assertHash(entry, blob; hashfunction)
101-
de = addDataEntry!(dfg, label, entry)
99+
de = addBlobEntry!(dfg, label, entry)
102100
db = addBlob!(blobstore, de, blob)
103101
return de=>db
104102
end
@@ -109,7 +107,7 @@ function updateBlob!(dfg::AbstractDFG, blobstore::AbstractBlobStore, label::Symb
109107
buildSourceString(dfg, label),
110108
entry.description, entry.mimeType, entry.metadata, entry.timestamp, entry._type, string(_getDFGVersion()))
111109

112-
de = updateDataEntry!(dfg, label, newEntry)
110+
de = updateBlobEntry!(dfg, label, newEntry)
113111
db = updateBlob!(blobstore, de, blob)
114112
return de=>db
115113
end

src/DataBlobs/services/InMemoryStore.jl

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,14 @@
44
## BlobEntry Blob CRUD - dit lyk nie of dit gebruik moet word nie
55
##==============================================================================
66

7-
getBlob(dfg::AbstractDFG, entry::BlobEntry) = (@error("Inmemory blobstore is not working"); return nothing) ## entry.data
8-
7+
# FIXME cannot overwrite regular getBlob etc functions
8+
# getBlob(dfg::AbstractDFG, entry::BlobEntry) = (@error("Inmemory blobstore is not working"); return nothing) ## entry.data
99
# addBlob!(dfg::AbstractDFG, entry::BlobEntry, blob) = error("Not suported")#entry.blob
1010
# updateBlob!(dfg::AbstractDFG, entry::BlobEntry, blob) = error("Not suported")#entry.blob
11-
deleteBlob!(dfg::AbstractDFG, entry::BlobEntry) = (@error("Inmemory blobstore is not working"); return nothing) ## entry.data
11+
# deleteBlob!(dfg::AbstractDFG, entry::BlobEntry) = (@error("Inmemory blobstore is not working"); return nothing) ## entry.data
12+
1213

13-
function addBlob!(dfg::AbstractDFG, label::Symbol, entry::BlobEntry; hashfunction = sha256)
14-
# assertHash(entry, entry.data, hashfunction=hashfunction)
15-
de = addBlobEntry!(dfg, label, entry)
16-
db = getBlob(dfg, entry)
17-
return de=>db
18-
end
1914

20-
function updateBlob!(dfg::AbstractDFG, label::Symbol, entry::BlobEntry)
21-
# assertHash(entry, entry.data, hashfunction=hashfunction)
22-
de = updateBlobEntry!(dfg, label, entry)
23-
db = getBlob(dfg, entry)
24-
return de=>db
25-
end
2615
##==============================================================================
2716
## BlobEntry CRUD Helpers
2817
##==============================================================================
29-
30-
# function addBlob!(dfg::AbstractDFG, label::Symbol, key::Symbol, folder::String, blob::Vector{UInt8}, timestamp=now(localzone());
31-
function addBlob!(::Type{BlobEntry}, dfg::AbstractDFG, label::Symbol, key::Symbol, blob, timestamp=now(localzone());
32-
id::UUID = uuid4(), hashfunction = sha256)
33-
fde = BlobEntry(key, id, timestamp, blob)
34-
de = addBlobEntry!(dfg, label, fde)
35-
return de=>blob
36-
end

src/Deprecated.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@
1919
@deprecate deleteDataBlob!(w...;kw...) deleteBlob!(w...;kw...)
2020
@deprecate listDataBlobs(w...;kw...) listBlobs(w...;kw...)
2121

22+
# function updateBlob!(
23+
# dfg::AbstractDFG,
24+
# label::Symbol,
25+
# entry::BlobEntry
26+
# )
27+
# # assertHash(entry, entry.data, hashfunction=hashfunction)
28+
# de = updateBlobEntry!(dfg, label, entry)
29+
# db = getBlob(dfg, entry)
30+
# return de=>db
31+
# end
32+
33+
# function addBlob!(
34+
# dfg::AbstractDFG,
35+
# label::Symbol,
36+
# entry::BlobEntry;
37+
# hashfunction = sha256
38+
# )
39+
# # assertHash(entry, entry.data, hashfunction=hashfunction)
40+
# de = addBlobEntry!(dfg, label, entry)
41+
# db = getBlob(dfg, entry)
42+
# return de=>db
43+
# end
44+
2245
## ================================================================================
2346
## Add @deprecate in v0.19, remove after v0.20
2447
##=================================================================================

src/FileDFG/services/FileDFG.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ function loadDFG!(dfgLoadInto::AbstractDFG, dst::AbstractString)
129129
@showprogress 1 "loading variables" for varFile in varFiles
130130
packedData = read("$varFolder/$varFile", String)
131131
packedData = JSON3.read(packedData, PackedVariable)
132-
@show packedData
133132
push!(variables, unpackVariable(packedData))
134133
end
135134
@info "Loaded $(length(variables)) variables - $(map(v->v.label, variables))"

src/services/Serialization.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ function fncStringToData(fncType::String, data::T) where {T <: AbstractPackedFac
298298
end
299299
function fncStringToData(fncType::String, data::Union{String, <:NamedTuple})
300300
packtype = DFG.getTypeFromSerializationModule("Packed"*fncType)
301-
@info "WHAT" packtype
302301
fncStringToData(packtype, data)
303302
end
304303

test/GraphsDFGSummaryTypes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# FACTYPE = DFGFactorSummary
44

55
dfg = GraphsDFG{NoSolverParams, VARTYPE, FACTYPE}()
6-
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(nothing, label, DistributedFactorGraphs.now(localzone()), Set{Symbol}(), Dict{Symbol, MeanMaxPPE}(), :Pose2, Dict{Symbol,AbstractDataEntry}())
6+
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(nothing, label, DistributedFactorGraphs.now(localzone()), Set{Symbol}(), Dict{Symbol, MeanMaxPPE}(), :Pose2, Dict{Symbol,BlobEntry}())
77
DistributedFactorGraphs.DFGFactorSummary(label::Symbol) = DFGFactorSummary(nothing, label, Set{Symbol}(), Symbol[], DistributedFactorGraphs.now(localzone()))
88

9-
DistributedFactorGraphs.DFGVariableSummary(label::Symbol, ::VariableNodeData{T}) where T = DFGVariableSummary(nothing, label, DistributedFactorGraphs.now(localzone()), Set{Symbol}(), Dict{Symbol, MeanMaxPPE}(), Symbol(T), Dict{Symbol,AbstractDataEntry}())
9+
DistributedFactorGraphs.DFGVariableSummary(label::Symbol, ::VariableNodeData{T}) where T = DFGVariableSummary(nothing, label, DistributedFactorGraphs.now(localzone()), Set{Symbol}(), Dict{Symbol, MeanMaxPPE}(), Symbol(T), Dict{Symbol,BlobEntry}())
1010
DistributedFactorGraphs.SkeletonDFGVariable(label::Symbol, args...) = SkeletonDFGVariable(label)
1111
DistributedFactorGraphs.SkeletonDFGVariable(label::Symbol, ::VariableNodeData{T}) where T = SkeletonDFGVariable(nothing, label, Set{Symbol}())
1212

test/consol_DataEntryBlobTests.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ using SHA
1010

1111
include("testBlocks.jl")
1212

13-
testDFGAPI = GraphsDFG
1413
end
14+
1515
# Build a basic graph.
1616

1717
testDFGAPI = GraphsDFG
@@ -157,15 +157,16 @@ store = TestStore{Int}()
157157
@test_throws ErrorException listBlobs(store)
158158

159159

160-
##==============================================================================
161-
## Unimplemented Entry Blob Crud
162-
##==============================================================================
163-
struct NotImplementedDE <: AbstractDataEntry end
160+
# Dropping use of AbstractDataEntry
161+
# ##==============================================================================
162+
# ## Unimplemented Entry Blob Crud
163+
# ##==============================================================================
164+
# struct NotImplementedDE <: AbstractDataEntry end
164165

165-
nde = NotImplementedDE()
166+
# nde = NotImplementedDE()
166167

167-
@test_throws ErrorException getBlobBlob(dfg, nde)
168-
@test_throws ErrorException addBlob!(dfg, nde, 1)
169-
@test_throws ErrorException updateBlob!(dfg, nde, 1)
170-
@test_throws ErrorException deleteBlob!(dfg, nde)
171-
@test_throws ErrorException listBlobs(dfg)
168+
# @test_throws ErrorException getBlobBlob(dfg, nde)
169+
# @test_throws ErrorException addBlob!(dfg, nde, 1)
170+
# @test_throws ErrorException updateBlob!(dfg, nde, 1)
171+
# @test_throws ErrorException deleteBlob!(dfg, nde)
172+
# @test_throws ErrorException listBlobs(dfg)

0 commit comments

Comments
 (0)