Skip to content

Commit fb83614

Browse files
Synex-whatellwu
authored andcommitted
Rest data info id list (#15)
* fix temp push * update version 5.2.1-SNAPSHOT * fix test case * add rest api,getDataInfoIdList,checkSumDataInfoIdList * add publisher dataInfoList return
1 parent 4e1cc58 commit fb83614

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

server/server/session/src/main/java/com/alipay/sofa/registry/server/session/resource/SessionDigestResource.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ public Map<String, Object> getPushSwitch() {
142142
return resultMap;
143143
}
144144

145+
@GET
146+
@Path("getDataInfoIdList")
147+
@Produces(MediaType.APPLICATION_JSON)
148+
public Collection<String> getDataInfoIdList() {
149+
Collection<String> ret = new ArrayList<>();
150+
ret.addAll(sessionInterests.getInterestDataInfoIds());
151+
ret.addAll(sessionDataStore.getStoreDataInfoIds());
152+
return sessionInterests.getInterestDataInfoIds();
153+
}
154+
155+
@GET
156+
@Path("checkSumDataInfoIdList")
157+
@Produces(MediaType.APPLICATION_JSON)
158+
public int checkSumDataInfoIdList() {
159+
return sessionInterests.getInterestDataInfoIds().hashCode()
160+
+ sessionDataStore.getStoreDataInfoIds().hashCode();
161+
}
162+
145163
private void fillServerList(String type,
146164
Map<String, Collection<? extends StoreData>> serverList,
147165
Collection<Publisher> publishers,

server/server/session/src/main/java/com/alipay/sofa/registry/server/session/store/DataStore.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,26 @@
2727
*/
2828
public interface DataStore extends DataManager<Publisher, String, String> {
2929

30+
/**
31+
* get all publishers by dataInfoId
32+
* @param dataInfoId
33+
* @return
34+
*/
3035
Collection<Publisher> getStoreDataByDataInfoId(String dataInfoId);
3136

37+
/***
38+
* get Publiser by registerId and dataInfoId
39+
* @param registerId
40+
* @param dataInfoId
41+
* @return
42+
*/
3243
Publisher queryById(String registerId, String dataInfoId);
3344

45+
/**
46+
* get all publisher dataInfoIds
47+
*
48+
* @return
49+
*/
50+
Collection<String> getStoreDataInfoIds();
51+
3452
}

server/server/session/src/main/java/com/alipay/sofa/registry/server/session/store/SessionDataStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ public Publisher queryById(String registerId, String dataInfoId) {
195195
return publishers.get(registerId);
196196
}
197197

198+
@Override
199+
public Collection<String> getStoreDataInfoIds() {
200+
return registry.keySet();
201+
}
202+
198203
@Override
199204
public long count() {
200205
AtomicLong count = new AtomicLong(0);

test/src/test/java/com/alipay/sofa/registry/test/resource/session/SessionDigestResourceTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
import java.util.ArrayList;
3838
import java.util.List;
3939
import java.util.Map;
40+
import java.util.Set;
4041

4142
import static com.alipay.sofa.registry.client.constants.ValueConstants.DEFAULT_GROUP;
4243
import static com.alipay.sofa.registry.common.model.constants.ValueConstants.DEFAULT_INSTANCE_ID;
4344
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
4445
import static org.junit.Assert.assertEquals;
46+
import static org.junit.Assert.assertTrue;
4547

4648
/**
4749
* @author xuanbei
@@ -167,4 +169,20 @@ public void testGetPushSwitch() {
167169
assertEquals(1, result.size());
168170
assertEquals("open", result.get("pushSwitch"));
169171
}
172+
173+
@Test
174+
public void testGetDataInfoIdList() {
175+
Set<String> result = sessionChannel.getWebTarget().path("digest/getDataInfoIdList")
176+
.request(APPLICATION_JSON).get(Set.class);
177+
178+
assertTrue(result.contains(DataInfo
179+
.toDataInfoId(dataId, DEFAULT_INSTANCE_ID, DEFAULT_GROUP)));
180+
}
181+
182+
@Test
183+
public void testCheckSumDataInfoIdList() {
184+
int result = sessionChannel.getWebTarget().path("digest/checkSumDataInfoIdList")
185+
.request(APPLICATION_JSON).get(int.class);
186+
assertTrue(result > 0);
187+
}
170188
}

0 commit comments

Comments
 (0)