Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 1-basic/dubbo-samples-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>


Expand Down
29 changes: 20 additions & 9 deletions 2-advanced/dubbo-samples-cache/case-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@
# 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.

from: app-builtin-zookeeper.yml

props:
project_name: dubbo-samples-cache
main_class: org.apache.dubbo.samples.cache.CacheProvider
zookeeper_port: 2181
dubbo_port: 20880

services:
cache-provider:
type: app
basedir: dubbo-samples-cache-provider
mainClass: org.apache.dubbo.samples.cache.CacheProvider
cache-consumer:
type: test
basedir: dubbo-samples-cache-consumer
tests:
- "**/*IT.class"
systemProps:
- zookeeper.address=cache-provider
- zookeeper.port=2181
- dubbo.address=cache-provider
- dubbo.port=20880
waitPortsBeforeRun:
- cache-provider:2181
- cache-provider:20880
depends_on:
- cache-provider
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dubbo-samples-cache</artifactId>
<groupId>org.apache.dubbo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dubbo-samples-cache-consumer</artifactId>

<dependencies>
<!-- dubbo -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<type>pom</type>
<exclusions>
<exclusion>
<artifactId>slf4j-reload4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>

<!-- spring starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-samples-cache-interface</artifactId>
<version>${project.parent.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
*
* 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 org.apache.dubbo.samples.cache;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableDubbo
public class CacheConsumer {
public static void main(String[] args) {
SpringApplication.run(CacheConsumer.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@

package org.apache.dubbo.samples.cache;

import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.samples.cache.api.CacheService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import org.springframework.context.support.ClassPathXmlApplicationContext;
@Component
public class Task implements CommandLineRunner {
@DubboReference(cache = "true")
CacheService cacheService;

public class CacheConsumer {

public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/cache-consumer.xml");
context.start();

CacheService cacheService = (CacheService) context.getBean("cacheService");

// verify cache, same result is returned for different invocations (in fact, the return value increases
// on every invocation on the server side)
@Override
public void run(String... args) {
System.out.println("ready to run task");
String fix = null;
cacheService.findCache("0");
for (int i = 0; i < 5; i++) {
Expand All @@ -43,7 +42,11 @@ public static void main(String[] args) throws Exception {
System.err.println("ERROR: " + result);
}
fix = result;
Thread.sleep(500);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

// default cache.size is 1000 for LRU, should have cache expired if invoke more than 1001 times
Expand All @@ -66,6 +69,7 @@ public static void main(String[] args) throws Exception {
} else {
System.err.println("ERROR: " + result);
}
}

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

dubbo:
application:
name: cache-consumer
qos-enable: false
protocol:
name: dubbo
port: -1
registry:
address: zookeeper://${zookeeper.address:127.0.0.1}:2181
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,30 @@

package org.apache.dubbo.samples.cache;

import org.apache.dubbo.samples.cache.api.CacheService;

import junit.framework.TestCase;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.samples.cache.api.CacheService;
import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:spring/cache-consumer.xml")

@SpringBootTest(classes = {DubboAutoConfiguration.class})
@RunWith(SpringRunner.class)
public class CacheServiceIT {
@Autowired
@Qualifier("cacheService")
@DubboReference(cache = "true")
private CacheService service;

@Test
public void findCache() throws Exception {
public void findCache() {
Assert.assertEquals(service.findCache("0"), service.findCache("0"));
}

@Test
public void verifyLRU() throws Exception {
public void verifyLRU() {
// this test is for LRU-2 cache only.
// verify cache, same result is returned for multiple invocations (in fact, the return value increases
// on every invocation on the server side)
Expand All @@ -60,6 +59,4 @@ public void verifyLRU() throws Exception {
TestCase.assertFalse(value.equals(service.findCache("0")));
TestCase.assertEquals(service.findCache("0"), service.findCache("0"));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dubbo-samples-cache</artifactId>
<groupId>org.apache.dubbo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dubbo-samples-cache-interface</artifactId>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
package org.apache.dubbo.samples.cache.api;

public interface CacheService {

String findCache(String id);

}
Loading