-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dubbo-1687]Enhance test coverage for dubbo filter (#1715)
* use three different kinds of cache factory to increase test coverages * add unit test cases for dubbo-filter module * add copyright and made small refactor * make sure Jcache will exceed expired period
- Loading branch information
Showing
7 changed files
with
213 additions
and
17 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
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
33 changes: 33 additions & 0 deletions
33
...-filter-cache/src/test/java/com/alibaba/dubbo/cache/support/AbstractCacheFactoryTest.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,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.dubbo.cache.support; | ||
|
||
import com.alibaba.dubbo.cache.Cache; | ||
import com.alibaba.dubbo.common.URL; | ||
import com.alibaba.dubbo.rpc.Invocation; | ||
import com.alibaba.dubbo.rpc.RpcInvocation; | ||
|
||
public abstract class AbstractCacheFactoryTest { | ||
|
||
protected Cache constructCache() { | ||
URL url = URL.valueOf("test://test:11/test?cache=lru"); | ||
Invocation invocation = new RpcInvocation(); | ||
return getCacheFactory().getCache(url, invocation); | ||
} | ||
|
||
protected abstract AbstractCacheFactory getCacheFactory(); | ||
} |
54 changes: 54 additions & 0 deletions
54
...-filter-cache/src/test/java/com/alibaba/dubbo/cache/support/jcache/JCacheFactoryTest.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,54 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.dubbo.cache.support.jcache; | ||
|
||
import com.alibaba.dubbo.cache.Cache; | ||
import com.alibaba.dubbo.cache.support.AbstractCacheFactory; | ||
import com.alibaba.dubbo.cache.support.AbstractCacheFactoryTest; | ||
import com.alibaba.dubbo.common.URL; | ||
import com.alibaba.dubbo.rpc.Invocation; | ||
import com.alibaba.dubbo.rpc.RpcInvocation; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class JCacheFactoryTest extends AbstractCacheFactoryTest { | ||
|
||
@Test | ||
public void testJCacheFactory() throws Exception { | ||
Cache cache = super.constructCache(); | ||
assertThat(cache instanceof JCache, is(true)); | ||
} | ||
|
||
@Test | ||
public void testJCacheGetExpired() throws Exception { | ||
URL url = URL.valueOf("test://test:11/test?cache=jacache&.cache.write.expire=1"); | ||
AbstractCacheFactory cacheFactory = getCacheFactory(); | ||
Invocation invocation = new RpcInvocation(); | ||
Cache cache = cacheFactory.getCache(url, invocation); | ||
cache.put("testKey", "testValue"); | ||
Thread.sleep(10); | ||
assertNull(cache.get("testKey")); | ||
} | ||
|
||
@Override | ||
protected AbstractCacheFactory getCacheFactory() { | ||
return new JCacheFactory(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...o-filter-cache/src/test/java/com/alibaba/dubbo/cache/support/lru/LruCacheFactoryTest.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,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.dubbo.cache.support.lru; | ||
|
||
import com.alibaba.dubbo.cache.Cache; | ||
import com.alibaba.dubbo.cache.support.AbstractCacheFactory; | ||
import com.alibaba.dubbo.cache.support.AbstractCacheFactoryTest; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class LruCacheFactoryTest extends AbstractCacheFactoryTest{ | ||
@Test | ||
public void testLruCacheFactory() throws Exception { | ||
Cache cache = super.constructCache(); | ||
assertThat(cache instanceof LruCache, is(true)); | ||
} | ||
|
||
@Override | ||
protected AbstractCacheFactory getCacheFactory() { | ||
return new LruCacheFactory(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...rc/test/java/com/alibaba/dubbo/cache/support/threadlocal/ThreadLocalCacheFactoryTest.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,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.dubbo.cache.support.threadlocal; | ||
|
||
import com.alibaba.dubbo.cache.Cache; | ||
import com.alibaba.dubbo.cache.support.AbstractCacheFactory; | ||
import com.alibaba.dubbo.cache.support.AbstractCacheFactoryTest; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class ThreadLocalCacheFactoryTest extends AbstractCacheFactoryTest { | ||
@Test | ||
public void testThreadLocalCacheFactory() throws Exception { | ||
Cache cache = super.constructCache(); | ||
assertThat(cache instanceof ThreadLocalCache, is(true)); | ||
} | ||
|
||
@Override | ||
protected AbstractCacheFactory getCacheFactory() { | ||
return new ThreadLocalCacheFactory(); | ||
} | ||
} |
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