Coverage Summary for Class: LogStoringDataCheckerImpl (cloud.mindbox.mobile_sdk.monitoring.data.checkers)

Class Method, % Branch, % Line, % Instruction, %
LogStoringDataCheckerImpl 100% (3/3) 42.9% (6/14) 61.5% (8/13) 63.2% (48/76)
LogStoringDataCheckerImpl$Companion 0% (0/2) 0% (0/2) 0% (0/6)
Total 60% (3/5) 42.9% (6/14) 53.3% (8/15) 58.5% (48/82)


 package cloud.mindbox.mobile_sdk.monitoring.data.checkers
 
 import cloud.mindbox.mobile_sdk.monitoring.domain.interfaces.LogStoringDataChecker
 import java.io.File
 import java.util.concurrent.atomic.AtomicBoolean
 
 internal class LogStoringDataCheckerImpl(private val dbFile: File) : LogStoringDataChecker {
 
     private var previousSize: Long? = null
 
     override fun isDatabaseMemorySizeExceeded(): Boolean {
         if (!dbFile.exists()) throw Exception("${dbFile.absolutePath} doesn't exist")
         val fileSize = dbFile.length()
         if (previousSize == null) previousSize = fileSize
         return if (needCleanLog.get()) {
             if (fileSize < MAX_LOG_SIZE || previousSize != fileSize) {
                 needCleanLog.set(false)
                 deletionIsInProgress.set(false)
                 previousSize = fileSize
             }
             false
         } else {
             fileSize >= MAX_LOG_SIZE
         }
     }
 
     companion object {
         /**
          * Ten megabytes in bytes. It is used as the maximum size of database in memory.
          *
          **/
         var needCleanLog: AtomicBoolean = AtomicBoolean(false)
         var deletionIsInProgress: AtomicBoolean = AtomicBoolean(false)
         const val MAX_LOG_SIZE = 10 * 1024 * 1024
     }
 }