File tree Expand file tree Collapse file tree 7 files changed +243
-0
lines changed Expand file tree Collapse file tree 7 files changed +243
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018 Google
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #import < Foundation/Foundation.h>
18
+
19
+ NS_ASSUME_NONNULL_BEGIN
20
+
21
+ /* * This class connects log storage and the backend implementations, providing logs to the uploaders
22
+ * and informing the log storage what logs were successfully uploaded or not.
23
+ */
24
+ @interface GDLUploader : NSObject
25
+
26
+ /* * Creates and/or returrns the singleton.
27
+ *
28
+ * @return The singleton instance of this class.
29
+ */
30
+ + (instancetype )sharedInstance ;
31
+
32
+ /* * Forces the backend specified by the target to upload the provided set of logs. This should only
33
+ * ever happen when the QoS tier of a log requires it.
34
+ */
35
+ - (void )forceUploadLogs : (NSSet <NSURL *> *)logFiles target : (NSInteger )logTarget ;
36
+
37
+ @end
38
+
39
+ NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018 Google
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #import " GDLUploader.h"
18
+
19
+ @implementation GDLUploader
20
+
21
+ + (instancetype )sharedInstance {
22
+ static GDLUploader *sharedUploader;
23
+ static dispatch_once_t onceToken;
24
+ dispatch_once (&onceToken, ^{
25
+ sharedUploader = [[GDLUploader alloc ] init ];
26
+ });
27
+ return sharedUploader;
28
+ }
29
+
30
+ - (void )forceUploadLogs : (NSSet <NSURL *> *)logFiles target : (NSInteger )logTarget {
31
+ // TODO
32
+ }
33
+
34
+ @end
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018 Google
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #import < XCTest/XCTest.h>
18
+
19
+ #import " GDLUploader.h"
20
+
21
+ @interface GDLUploaderTest : XCTestCase
22
+
23
+ @end
24
+
25
+ @implementation GDLUploaderTest
26
+
27
+ /* * Tests the default initializer. */
28
+ - (void )testSharedInstance {
29
+ XCTAssertEqual ([GDLUploader sharedInstance ], [GDLUploader sharedInstance ]);
30
+ }
31
+
32
+ @end
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018 Google
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #import < Foundation/Foundation.h>
18
+
19
+ #import " GDLLogBackend.h"
20
+
21
+ NS_ASSUME_NONNULL_BEGIN
22
+
23
+ /* * This class implements the log backend protocol for testing purposes, providing APIs to allow
24
+ * tests to alter the uploader behavior without creating a bunch of specialized classes.
25
+ */
26
+ @interface GDLTestBackend : NSObject <GDLLogBackend>
27
+
28
+ /* * A block that can be ran in -uploadLogs:onComplete:. */
29
+ @property (nullable , nonatomic ) void (^uploadLogsBlock)
30
+ (NSSet <NSURL *> *logFiles, GDLBackendCompletionBlock completionBlock);
31
+
32
+ @end
33
+
34
+ NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018 Google
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #import " GDLTestBackend.h"
18
+
19
+ @implementation GDLTestBackend
20
+
21
+ - (void )uploadLogs : (NSSet <NSURL *> *)logFiles onComplete : (GDLBackendCompletionBlock)onComplete {
22
+ if (_uploadLogsBlock) {
23
+ _uploadLogsBlock (logFiles, onComplete);
24
+ } else if (onComplete) {
25
+ onComplete (nil , nil );
26
+ }
27
+ }
28
+
29
+ @end
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018 Google
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #import < Foundation/Foundation.h>
18
+
19
+ #import < GoogleDataLogger/GDLLogPrioritizer.h>
20
+
21
+ NS_ASSUME_NONNULL_BEGIN
22
+
23
+ /* * This class implements the log prioritizer protocol for testing purposes, providing APIs to allow
24
+ * tests to alter the prioritizer behavior without creating a bunch of specialized classes.
25
+ */
26
+ @interface GDLTestPrioritizer : NSObject <GDLLogPrioritizer>
27
+
28
+ /* * The return value of -logsForNextUpload. */
29
+ @property (nullable , nonatomic ) NSSet <NSNumber *> *logsForNextUploadFake;
30
+
31
+ /* * Allows the running of a block of code during -prioritizeLog. */
32
+ @property (nullable , nonatomic ) void (^prioritizeLogBlock)(GDLLogEvent *logEvent);
33
+
34
+ @end
35
+
36
+ NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2018 Google
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #import " GDLTestPrioritizer.h"
18
+
19
+ @implementation GDLTestPrioritizer
20
+
21
+ - (instancetype )init {
22
+ self = [super init ];
23
+ if (self) {
24
+ _logsForNextUploadFake = [[NSSet alloc ] init ];
25
+ }
26
+ return self;
27
+ }
28
+
29
+ - (NSSet <NSNumber *> *)logsForNextUpload {
30
+ return _logsForNextUploadFake;
31
+ }
32
+
33
+ - (void )prioritizeLog : (GDLLogEvent *)logEvent {
34
+ if (_prioritizeLogBlock) {
35
+ _prioritizeLogBlock (logEvent);
36
+ }
37
+ }
38
+
39
+ @end
You can’t perform that action at this time.
0 commit comments