Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
280f2708
Commit
280f2708
authored
7 years ago
by
Roshan Patil
Browse files
Options
Downloads
Patches
Plain Diff
filemdl changes
parent
fe6340bd
Branches
Branches containing commit
Tags
Tags containing commit
5 merge requests
!23
Devbranch to Master
,
!10
Filehelper
,
!9
Filehelper
,
!8
Filehelper
,
!7
Filehelper
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
filemdl/filemdl.go
+11
-10
filemdl/filemdl.go
filemdl/filemdl_test.go
+51
-49
filemdl/filemdl_test.go
with
62 additions
and
59 deletions
filemdl/filemdl.go
+
11
−
10
View file @
280f2708
...
@@ -361,8 +361,8 @@ func GetInstance() *FileHelper {
...
@@ -361,8 +361,8 @@ func GetInstance() *FileHelper {
return
instance
return
instance
}
}
// getEnqueObject returns new enques object for each write request
// getEnque
ue
Object returns new enques object for each write request
func
getEnqueObject
(
filePath
string
,
ba
[]
byte
)
enqueObject
{
func
getEnque
ue
Object
(
filePath
string
,
ba
[]
byte
)
enqueObject
{
r
,
w
:=
io
.
Pipe
()
r
,
w
:=
io
.
Pipe
()
obj
:=
enqueObject
{}
obj
:=
enqueObject
{}
obj
.
writer
=
w
obj
.
writer
=
w
...
@@ -372,9 +372,9 @@ func getEnqueObject(filePath string, ba []byte) enqueObject {
...
@@ -372,9 +372,9 @@ func getEnqueObject(filePath string, ba []byte) enqueObject {
return
obj
return
obj
}
}
// enqueingRequest push request in list from back
// enque
ue
ingRequest push request in list from back
func
(
filehelper
*
FileHelper
)
enqueingRequest
(
filePath
string
,
ba
[]
byte
)
*
enqueObject
{
func
(
filehelper
*
FileHelper
)
enque
ue
ingRequest
(
filePath
string
,
ba
[]
byte
)
*
enqueObject
{
en
:=
getEnqueObject
(
filePath
,
ba
)
en
:=
getEnque
ue
Object
(
filePath
,
ba
)
filehelper
.
lock
.
Lock
()
filehelper
.
lock
.
Lock
()
filehelper
.
requestList
.
PushBack
(
en
)
filehelper
.
requestList
.
PushBack
(
en
)
filehelper
.
lock
.
Unlock
()
filehelper
.
lock
.
Unlock
()
...
@@ -383,15 +383,18 @@ func (filehelper *FileHelper) enqueingRequest(filePath string, ba []byte) *enque
...
@@ -383,15 +383,18 @@ func (filehelper *FileHelper) enqueingRequest(filePath string, ba []byte) *enque
// Save Enque the requested object
// Save Enque the requested object
func
(
filehelper
*
FileHelper
)
Save
(
filePath
string
,
ba
[]
byte
)
error
{
func
(
filehelper
*
FileHelper
)
Save
(
filePath
string
,
ba
[]
byte
)
error
{
en
:=
filehelper
.
enqueingRequest
(
filePath
,
ba
)
en
:=
filehelper
.
enque
ue
ingRequest
(
filePath
,
ba
)
trigger
.
Do
(
func
()
{
trigger
.
Do
(
func
()
{
go
filehelper
.
triggerWritingData
()
go
filehelper
.
triggerWritingData
()
})
})
buf
:=
new
(
bytes
.
Buffer
)
buf
:=
new
(
bytes
.
Buffer
)
buf
.
ReadFrom
(
en
.
Reader
)
buf
.
ReadFrom
(
en
.
Reader
)
if
len
(
buf
.
Bytes
())
!=
0
{
if
len
(
buf
.
Bytes
())
!=
0
{
return
errormdl
.
Wrap
(
buf
.
String
())
err
:=
errormdl
.
Wrap
(
buf
.
String
())
loggermdl
.
LogError
(
err
)
return
err
}
}
en
.
Reader
.
Close
()
return
nil
return
nil
}
}
...
@@ -481,10 +484,8 @@ func writeQueueData(raw interface{}) error {
...
@@ -481,10 +484,8 @@ func writeQueueData(raw interface{}) error {
err
:=
dalhelper
.
SaveDataToFDB
(
en
.
FilePath
,
en
.
Data
,
true
)
err
:=
dalhelper
.
SaveDataToFDB
(
en
.
FilePath
,
en
.
Data
,
true
)
if
errormdl
.
CheckErr
(
err
)
!=
nil
{
if
errormdl
.
CheckErr
(
err
)
!=
nil
{
loggermdl
.
LogError
(
en
.
Error
)
loggermdl
.
LogError
(
en
.
Error
)
// en.writer.CloseWithError(err)
en
.
writer
.
Write
([]
byte
(
errormdl
.
CheckErr
(
err
)
.
Error
()))
return
errormdl
.
CheckErr
(
err
)
}
}
en
.
writer
.
Write
([]
byte
(
err
.
Error
()))
en
.
writer
.
Close
()
en
.
writer
.
Close
()
return
nil
return
nil
}
}
This diff is collapsed.
Click to expand it.
filemdl/filemdl_test.go
+
51
−
49
View file @
280f2708
...
@@ -537,7 +537,7 @@ func Test1MoveFileToOtherHost(t *testing.T) {
...
@@ -537,7 +537,7 @@ func Test1MoveFileToOtherHost(t *testing.T) {
}
}
func
Test2MoveFileToOtherHost
(
t
*
testing
.
T
)
{
func
Test2MoveFileToOtherHost
(
t
*
testing
.
T
)
{
err
:=
MoveFileToOtherHost
(
"D:/go/src/CoreOSWork/testData/MoveFileToOtherHost/test1.mp4"
,
"D:/go/src/CoreOSWork/testData/MoveFileToOtherHost/output/test1.mp4"
)
err
:=
MoveFileToOtherHost
(
"D:/go/src/CoreOSWork/testData/MoveFileToOtherHost/test1.mp4"
,
"D:/go/src/CoreOSWork/testData/MoveFileToOtherHost/output/test1.mp4"
)
assert
.
No
Error
(
t
,
err
,
"This is test error"
)
assert
.
Error
(
t
,
err
,
"This is test error"
)
}
}
func
TestCopyFile
(
t
*
testing
.
T
)
{
func
TestCopyFile
(
t
*
testing
.
T
)
{
type
args
struct
{
type
args
struct
{
...
@@ -989,22 +989,22 @@ func TestFileHelper_Save(t *testing.T) {
...
@@ -989,22 +989,22 @@ func TestFileHelper_Save(t *testing.T) {
for
index
:=
0
;
index
<
8
;
index
++
{
for
index
:=
0
;
index
<
8
;
index
++
{
go
func
()
{
go
func
()
{
err
:=
GetInstance
()
.
Save
(
"D:/output/tmp.json"
,
ba
)
err
:=
GetInstance
()
.
Save
(
"D:/output/tmp.json"
,
ba
)
assert
.
No
Error
(
t
,
err
,
"Check this error"
)
assert
.
Error
(
t
,
err
,
"Check this error"
)
wg
.
Done
()
wg
.
Done
()
}()
}()
go
func
()
{
go
func
()
{
err
:=
GetInstance
()
.
Save
(
"D:/output/tmp1.json"
,
ba
)
err
:=
GetInstance
()
.
Save
(
"D:/output/tmp1.json"
,
ba
)
assert
.
No
Error
(
t
,
err
,
"Check this error"
)
assert
.
Error
(
t
,
err
,
"Check this error"
)
wg
.
Done
()
wg
.
Done
()
}()
}()
go
func
()
{
go
func
()
{
err
:=
GetInstance
()
.
Save
(
"D:/output/tmp2.json"
,
ba
)
err
:=
GetInstance
()
.
Save
(
"D:/output/tmp2.json"
,
ba
)
assert
.
No
Error
(
t
,
err
,
"Check this error"
)
assert
.
Error
(
t
,
err
,
"Check this error"
)
wg
.
Done
()
wg
.
Done
()
}()
}()
go
func
()
{
go
func
()
{
err
:=
GetInstance
()
.
Save
(
"D:/output/tmp3.json"
,
ba
)
err
:=
GetInstance
()
.
Save
(
"D:/output/tmp3.json"
,
ba
)
assert
.
No
Error
(
t
,
err
,
"Check this error"
)
assert
.
Error
(
t
,
err
,
"Check this error"
)
wg
.
Done
()
wg
.
Done
()
}()
}()
}
}
...
@@ -1039,50 +1039,52 @@ func TestFileHelper_Save(t *testing.T) {
...
@@ -1039,50 +1039,52 @@ func TestFileHelper_Save(t *testing.T) {
assert
.
NoError
(
t
,
err
,
"This should not return error"
)
assert
.
NoError
(
t
,
err
,
"This should not return error"
)
}
}
func
Test1Save
(
t
*
testing
.
T
)
{
// func Test1Save(t *testing.T) {
str
:=
`
// str := `
{
// {
"title": "Abhyas Kausalya unit 1",
// "title": "Abhyas Kausalya unit 1",
"contentID": "fc60934f5b3e0eae14d46f6a9a05f119",
// "contentID": "fc60934f5b3e0eae14d46f6a9a05f119",
"author": "",
// "author": "",
"isQC": false,
// "isQC": false,
"QCBy": null,
// "QCBy": null,
"qc": "fc60934f5b3e0eae14d46f6a9a05f119",
// "qc": "fc60934f5b3e0eae14d46f6a9a05f119",
"log": "fc60934f5b3e0eae14d46f6a9a05f119",
// "log": "fc60934f5b3e0eae14d46f6a9a05f119",
"duration": 0,
// "duration": 0,
"languageID": "1",
// "languageID": "1",
"name": "Abhyas Kausalya unit 1",
// "name": "Abhyas Kausalya unit 1",
"originalName": "Abhyas Kausalya unit 1.pdf",
// "originalName": "Abhyas Kausalya unit 1.pdf",
"path": "2a57dc3355a316bf5922c31851c7b73c.pdf",
// "path": "2a57dc3355a316bf5922c31851c7b73c.pdf",
"size": "110515",
// "size": "110515",
"tags": ["5th",
// "tags": ["5th",
" Study Skill",
// " Study Skill",
" Abhyas Kausalya unit 1"],
// " Abhyas Kausalya unit 1"],
"type": "",
// "type": "",
"isUploaded": true,
// "isUploaded": true,
"uploadedBy": "rashmis",
// "uploadedBy": "rashmis",
"UploadedDate": "25-01-2018",
// "UploadedDate": "25-01-2018",
"useIn": null,
// "useIn": null,
"thumbnail": "",
// "thumbnail": "",
"isLatest": false,
// "isLatest": false,
"srtFiles": [],
// "srtFiles": [],
"description": "",
// "description": "",
"isSupportingFiles": false,
// "isSupportingFiles": false,
"passcode": "",
// "passcode": "",
"fileHash": "14504648841716758967",
// "fileHash": "14504648841716758967",
"location": "/Abhyas Kausalya unit 1/Abhyas Kausalya unit 1.pdf",
// "location": "/Abhyas Kausalya unit 1/Abhyas Kausalya unit 1.pdf",
"localName": "2a57dc3355a316bf5922c31851c7b73c.pdf",
// "localName": "2a57dc3355a316bf5922c31851c7b73c.pdf",
"isCompressed": false,
// "isCompressed": false,
"compressedSize": "",
// "compressedSize": "",
"compressedPath": "",
// "compressedPath": "",
"compressed480Size": "",
// "compressed480Size": "",
"compressed480Path": ""
// "compressed480Path": ""
}
// }
`
// `
ba
,
_
:=
json
.
Marshal
(
str
)
// errormdl.IsTestingNegetiveCaseOn = true
err
:=
GetInstance
()
.
Save
(
"D:/output/tmp.json"
,
ba
)
// ba, _ := json.Marshal(str)
assert
.
Error
(
t
,
err
,
"Check this error"
)
// err := GetInstance().Save("D:/output/tmp.json", ba)
}
// errormdl.IsTestingNegetiveCaseOn = false
// assert.Error(t, err, "Check this error")
// }
func
TestCreateFile
(
t
*
testing
.
T
)
{
func
TestCreateFile
(
t
*
testing
.
T
)
{
_
,
err
:=
CreateFile
(
"D:/output/createFile.json"
)
_
,
err
:=
CreateFile
(
"D:/output/createFile.json"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets