-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 in XP/xp-v-golden-gate from shawn/FC-6076_gg_m…
…etric_xp to master * commit '7d247d15a069b29b3d9c1ed33257826c7149755e': FC-6076: add unit tests FC-6076: add gg natice exception
- Loading branch information
Showing
4 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...nGateBindings/src/main/kotlin/com/fitbit/goldengate/bindings/GoldenGateNativeException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.fitbit.goldengate.bindings | ||
|
||
open class GoldenGateNativeException( | ||
val title: String, | ||
val nakCode: Int, | ||
val nakNameSpace: String = "gg.result", | ||
val nakMessage: String? = null, | ||
cause: Throwable? = null | ||
): Throwable(title, cause) |
54 changes: 54 additions & 0 deletions
54
...ldenGateBindings/src/main/kotlin/com/fitbit/goldengate/bindings/GoldenGateNativeResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.fitbit.goldengate.bindings | ||
|
||
private const val GG_ERROR_BASE = -10000 | ||
|
||
enum class GoldenGateNativeResult(val code: Int, val title: String) { | ||
GG_SUCCESS (( 0), "the operation or call succeeded"), | ||
GG_FAILURE (( -1), "an unspecified failure"), | ||
GG_ERROR_OUT_OF_MEMORY ((GG_ERROR_BASE - 0), "Out of memory"), | ||
GG_ERROR_OUT_OF_RESOURCES ((GG_ERROR_BASE - 1), "Out of resources"), | ||
GG_ERROR_INTERNAL ((GG_ERROR_BASE - 2), "Internal error"), | ||
GG_ERROR_INVALID_PARAMETERS ((GG_ERROR_BASE - 3), "Invalid parameters"), | ||
GG_ERROR_INVALID_STATE ((GG_ERROR_BASE - 4), "Invalid state"), | ||
GG_ERROR_NOT_IMPLEMENTED ((GG_ERROR_BASE - 5), "Not implemented"), | ||
GG_ERROR_OUT_OF_RANGE ((GG_ERROR_BASE - 6), "Out of range"), | ||
GG_ERROR_ACCESS_DENIED ((GG_ERROR_BASE - 7), "Access denied"), | ||
GG_ERROR_INVALID_SYNTAX ((GG_ERROR_BASE - 8), "Invalid syntax"), | ||
GG_ERROR_NOT_SUPPORTED ((GG_ERROR_BASE - 9), "Not supported"), | ||
GG_ERROR_INVALID_FORMAT ((GG_ERROR_BASE - 10), "Invalid format"), | ||
GG_ERROR_NOT_ENOUGH_SPACE ((GG_ERROR_BASE - 11), "Not enough space"), | ||
GG_ERROR_NO_SUCH_ITEM ((GG_ERROR_BASE - 12), "No such item (item not found)"), | ||
GG_ERROR_OVERFLOW ((GG_ERROR_BASE - 13), "Overflow"), | ||
GG_ERROR_TIMEOUT ((GG_ERROR_BASE - 14), "A timeout occurred"), | ||
GG_ERROR_WOULD_BLOCK ((GG_ERROR_BASE - 15), "The operation would block / try again later"), | ||
GG_ERROR_PERMISSION_DENIED ((GG_ERROR_BASE - 16), "Permission denied"), | ||
GG_ERROR_INTERRUPTED ((GG_ERROR_BASE - 17), "Operation interrupted"), | ||
GG_ERROR_IN_USE ((GG_ERROR_BASE - 18), "Resource already in use"), | ||
GG_ERROR_BASE_IO ((GG_ERROR_BASE - 100), "I/O related error"), | ||
GG_ERROR_BASE_SOCKET ((GG_ERROR_BASE - 200), "Socket related error"), | ||
GG_ERROR_BASE_COAP ((GG_ERROR_BASE - 300), "CoAP related error"), | ||
GG_ERROR_BASE_REMOTE ((GG_ERROR_BASE - 400), "Remote API related error"), | ||
GG_ERROR_BASE_GATTLINK ((GG_ERROR_BASE - 500), "Gattlink related error"), | ||
GG_ERROR_BASE_TLS ((GG_ERROR_BASE - 600), "TLS related error"); | ||
|
||
companion object { | ||
fun getNativeResultFrom(code: Int): GoldenGateNativeResult{ | ||
return when(code) { | ||
in 0 .. Int.MAX_VALUE -> return GG_SUCCESS | ||
in -10099 .. -1 -> { | ||
for (value in values()) { | ||
if (value.code == code) return value | ||
} | ||
GG_FAILURE | ||
} | ||
in -10199 .. -10100 -> GG_ERROR_BASE_IO | ||
in -10299 .. -10200 -> GG_ERROR_BASE_SOCKET | ||
in -10399 .. -10300 -> GG_ERROR_BASE_COAP | ||
in -10499 .. -10400 -> GG_ERROR_BASE_REMOTE | ||
in -10599 .. -10500 -> GG_ERROR_BASE_GATTLINK | ||
in -10699 .. -10600 -> GG_ERROR_BASE_TLS | ||
else -> GG_FAILURE | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...GateBindings/src/test/kotlin/com/fitbit/goldengate/bindings/GoldenGateNativeResultTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.fitbit.goldengate.bindings | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Test | ||
|
||
class GoldenGateNativeResultTest { | ||
|
||
@Test | ||
fun `should convert error code to GoldenGateNativeResult enum constant`() { | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(0), GoldenGateNativeResult.GG_SUCCESS) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(100), GoldenGateNativeResult.GG_SUCCESS) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-1), GoldenGateNativeResult.GG_FAILURE) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-100), GoldenGateNativeResult.GG_FAILURE) | ||
|
||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10000), GoldenGateNativeResult.GG_ERROR_OUT_OF_MEMORY) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10013), GoldenGateNativeResult.GG_ERROR_OVERFLOW) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10018), GoldenGateNativeResult.GG_ERROR_IN_USE) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10099), GoldenGateNativeResult.GG_FAILURE) | ||
|
||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10100), GoldenGateNativeResult.GG_ERROR_BASE_IO) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10199), GoldenGateNativeResult.GG_ERROR_BASE_IO) | ||
|
||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10200), GoldenGateNativeResult.GG_ERROR_BASE_SOCKET) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10299), GoldenGateNativeResult.GG_ERROR_BASE_SOCKET) | ||
|
||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10300), GoldenGateNativeResult.GG_ERROR_BASE_COAP) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10399), GoldenGateNativeResult.GG_ERROR_BASE_COAP) | ||
|
||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10400), GoldenGateNativeResult.GG_ERROR_BASE_REMOTE) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10499), GoldenGateNativeResult.GG_ERROR_BASE_REMOTE) | ||
|
||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10500), GoldenGateNativeResult.GG_ERROR_BASE_GATTLINK) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10599), GoldenGateNativeResult.GG_ERROR_BASE_GATTLINK) | ||
|
||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10600), GoldenGateNativeResult.GG_ERROR_BASE_TLS) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10699), GoldenGateNativeResult.GG_ERROR_BASE_TLS) | ||
|
||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(-10700), GoldenGateNativeResult.GG_FAILURE) | ||
|
||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(Int.MAX_VALUE), GoldenGateNativeResult.GG_SUCCESS) | ||
assertEquals(GoldenGateNativeResult.getNativeResultFrom(Int.MIN_VALUE), GoldenGateNativeResult.GG_FAILURE) | ||
} | ||
} |