Skip to content

Commit

Permalink
Rest data info id list (#15)
Browse files Browse the repository at this point in the history
* fix temp push

* update version 5.2.1-SNAPSHOT

* fix test case

* add rest api,getDataInfoIdList,checkSumDataInfoIdList

* add publisher dataInfoList return
  • Loading branch information
Synex-wh authored and atellwu committed Apr 29, 2019
1 parent 4e1cc58 commit fb83614
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ public Map<String, Object> getPushSwitch() {
return resultMap;
}

@GET
@Path("getDataInfoIdList")
@Produces(MediaType.APPLICATION_JSON)
public Collection<String> getDataInfoIdList() {
Collection<String> ret = new ArrayList<>();
ret.addAll(sessionInterests.getInterestDataInfoIds());
ret.addAll(sessionDataStore.getStoreDataInfoIds());
return sessionInterests.getInterestDataInfoIds();
}

@GET
@Path("checkSumDataInfoIdList")
@Produces(MediaType.APPLICATION_JSON)
public int checkSumDataInfoIdList() {
return sessionInterests.getInterestDataInfoIds().hashCode()
+ sessionDataStore.getStoreDataInfoIds().hashCode();
}

private void fillServerList(String type,
Map<String, Collection<? extends StoreData>> serverList,
Collection<Publisher> publishers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,26 @@
*/
public interface DataStore extends DataManager<Publisher, String, String> {

/**
* get all publishers by dataInfoId
* @param dataInfoId
* @return
*/
Collection<Publisher> getStoreDataByDataInfoId(String dataInfoId);

/***
* get Publiser by registerId and dataInfoId
* @param registerId
* @param dataInfoId
* @return
*/
Publisher queryById(String registerId, String dataInfoId);

/**
* get all publisher dataInfoIds
*
* @return
*/
Collection<String> getStoreDataInfoIds();

}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ public Publisher queryById(String registerId, String dataInfoId) {
return publishers.get(registerId);
}

@Override
public Collection<String> getStoreDataInfoIds() {
return registry.keySet();
}

@Override
public long count() {
AtomicLong count = new AtomicLong(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.alipay.sofa.registry.client.constants.ValueConstants.DEFAULT_GROUP;
import static com.alipay.sofa.registry.common.model.constants.ValueConstants.DEFAULT_INSTANCE_ID;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author xuanbei
Expand Down Expand Up @@ -167,4 +169,20 @@ public void testGetPushSwitch() {
assertEquals(1, result.size());
assertEquals("open", result.get("pushSwitch"));
}

@Test
public void testGetDataInfoIdList() {
Set<String> result = sessionChannel.getWebTarget().path("digest/getDataInfoIdList")
.request(APPLICATION_JSON).get(Set.class);

assertTrue(result.contains(DataInfo
.toDataInfoId(dataId, DEFAULT_INSTANCE_ID, DEFAULT_GROUP)));
}

@Test
public void testCheckSumDataInfoIdList() {
int result = sessionChannel.getWebTarget().path("digest/checkSumDataInfoIdList")
.request(APPLICATION_JSON).get(int.class);
assertTrue(result > 0);
}
}

0 comments on commit fb83614

Please sign in to comment.