-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
377 additions
and
16 deletions.
There are no files selected for viewing
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,29 @@ | ||
name: Codecov CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up JDK 18 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 18 | ||
- name: Install dependencies | ||
run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V | ||
- name: Run tests and collect coverage | ||
run: mvn -B test | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v4 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
17 changes: 17 additions & 0 deletions
17
...s/klein-consensus-paxos/src/test/java/com/ofcoder/klein/consensus/paxos/ProposalTest.java
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,17 @@ | ||
package com.ofcoder.klein.consensus.paxos; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class ProposalTest extends TestCase { | ||
|
||
public void testGetGroup() { | ||
Proposal proposal = new Proposal(); | ||
assertNull(proposal.getGroup()); | ||
|
||
proposal = new Proposal("group1", "data1"); | ||
assertEquals("group1", proposal.getGroup()); | ||
|
||
proposal.setGroup("group2"); | ||
assertEquals("group2", proposal.getGroup()); | ||
} | ||
} |
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
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
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
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
15 changes: 15 additions & 0 deletions
15
klein-core/src/test/java/com/ofcoder/klein/KleinPropTest.java
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,15 @@ | ||
package com.ofcoder.klein; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class KleinPropTest { | ||
|
||
@Test | ||
public void testGetStorage() { | ||
KleinProp prop = new KleinProp(); | ||
Assert.assertEquals("file", prop.getStorage()); | ||
prop.setStorage("leveldb"); | ||
Assert.assertEquals("leveldb", prop.getStorage()); | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
klein-core/src/test/java/com/ofcoder/klein/core/cache/CacheSMTest.java
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,117 @@ | ||
package com.ofcoder.klein.core.cache; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.mockito.Mockito.any; | ||
import static org.mockito.Mockito.anyLong; | ||
import static org.mockito.Mockito.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class CacheSMTest { | ||
|
||
CacheSM cacheSM; | ||
|
||
@Mock | ||
private CacheContainer mockContainer; | ||
|
||
@Before | ||
public void setUp() throws NoSuchFieldException, IllegalAccessException { | ||
MockitoAnnotations.initMocks(this); | ||
cacheSM = new CacheSM(new CacheProp()) { | ||
@Override | ||
public Object makeImage() { | ||
return mockContainer; | ||
} | ||
}; | ||
|
||
Field containerField = CacheSM.class.getDeclaredField("container"); | ||
containerField.setAccessible(true); | ||
containerField.set(cacheSM, mockContainer); | ||
} | ||
|
||
@Test | ||
public void testApplyWithPutOperation() { | ||
CacheMessage message = new CacheMessage(); | ||
message.setOp(CacheMessage.PUT); | ||
message.setKey("key"); | ||
message.setData("data"); | ||
message.setExpire(1000L); | ||
|
||
cacheSM.apply(message); | ||
verify(mockContainer).put(eq("key"), eq("data"), eq(1000L)); | ||
} | ||
|
||
@Test | ||
public void testApplyWithGetOperation() { | ||
CacheMessage message = new CacheMessage(); | ||
message.setOp(CacheMessage.GET); | ||
message.setKey("key"); | ||
|
||
when(mockContainer.get("key")).thenReturn("data"); | ||
|
||
assertEquals("data", cacheSM.apply(message)); | ||
} | ||
|
||
@Test | ||
public void testApplyWithInvalidateOperation() { | ||
CacheMessage message = new CacheMessage(); | ||
message.setOp(CacheMessage.INVALIDATE); | ||
message.setKey("key"); | ||
|
||
cacheSM.apply(message); | ||
verify(mockContainer).remove("key"); | ||
} | ||
|
||
@Test | ||
public void testApplyWithInvalidateAllOperation() { | ||
CacheMessage message = new CacheMessage(); | ||
message.setOp(CacheMessage.INVALIDATEALL); | ||
|
||
cacheSM.apply(message); | ||
verify(mockContainer).clear(); | ||
} | ||
|
||
@Test | ||
public void testApplyWithPutIfPresentOperation() { | ||
CacheMessage message = new CacheMessage(); | ||
message.setOp(CacheMessage.PUTIFPRESENT); | ||
message.setKey("key"); | ||
message.setData("data"); | ||
message.setExpire(1000L); | ||
|
||
when(mockContainer.putIfAbsent("key", "data", 1000L)).thenReturn(true); | ||
|
||
assertEquals(true, cacheSM.apply(message)); | ||
} | ||
|
||
@Test | ||
public void testApplyWithExistOperation() { | ||
CacheMessage message = new CacheMessage(); | ||
message.setOp(CacheMessage.EXIST); | ||
message.setKey("key"); | ||
|
||
when(mockContainer.containsKey("key")).thenReturn(true); | ||
|
||
assertEquals(true, cacheSM.apply(message)); | ||
} | ||
|
||
|
||
@Test | ||
public void testApplyWithUnknownMessage() { | ||
assertNull(cacheSM.apply(new Object())); | ||
verify(mockContainer, never()).put(any(), any(), anyLong()); | ||
verify(mockContainer, never()).get(any()); | ||
verify(mockContainer, never()).remove(any()); | ||
verify(mockContainer, never()).clear(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
klein-core/src/test/java/com/ofcoder/klein/core/cache/CacheSnapTest.java
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,25 @@ | ||
package com.ofcoder.klein.core.cache; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class CacheSnapTest { | ||
|
||
CacheSnap cacheSnap; | ||
|
||
Object cache; | ||
|
||
@Before | ||
public void setUp() { | ||
cache = mock(Object.class); | ||
cacheSnap = new CacheSnap(cache, null); | ||
} | ||
|
||
@Test | ||
public void testGetCache() { | ||
assertEquals(cache, cacheSnap.getCache()); | ||
} | ||
} |
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
Oops, something went wrong.