当前位置: 首页>>代码示例>>Java>>正文


Java ZkStateReader.toJSON方法代码示例

本文整理汇总了Java中org.apache.solr.common.cloud.ZkStateReader.toJSON方法的典型用法代码示例。如果您正苦于以下问题:Java ZkStateReader.toJSON方法的具体用法?Java ZkStateReader.toJSON怎么用?Java ZkStateReader.toJSON使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.common.cloud.ZkStateReader的用法示例。


在下文中一共展示了ZkStateReader.toJSON方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDefaultSliceState

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
@Test
public void testDefaultSliceState() throws Exception {
  Map<String, DocCollection> collectionStates = new HashMap<>();
  Set<String> liveNodes = new HashSet<>();
  liveNodes.add("node1");

  Map<String, Slice> slices = new HashMap<>();
  Map<String, Replica> sliceToProps = new HashMap<>();
  Map<String, Object> props = new HashMap<>();

  Replica replica = new Replica("node1", props);
  sliceToProps.put("node1", replica);
  Slice slice = new Slice("shard1", sliceToProps, null);
  assertEquals("Default state not set to active", Slice.ACTIVE, slice.getState());
  slices.put("shard1", slice);
  collectionStates.put("collection1", new DocCollection("collection1", slices, null, DocRouter.DEFAULT));

  ZkStateReader mockZkStateReader = ClusterStateTest.getMockZkStateReader(collectionStates.keySet());
  ClusterState clusterState = new ClusterState(-1,liveNodes, collectionStates);
  byte[] bytes = ZkStateReader.toJSON(clusterState);
  ClusterState loadedClusterState = ClusterState.load(-1, bytes, liveNodes);

  assertEquals("Default state not set to active", "active", loadedClusterState.getSlice("collection1", "shard1").getState());
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:SliceStateTest.java

示例2: testBasic

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
@Test
public void testBasic() throws IOException {
  
  Map<String,Object> props = new HashMap<>();
  props.put("prop1", "value1");
  props.put("prop2", "value2");
  props.put("prop3", "value3");
  props.put("prop4", "value4");
  props.put("prop5", "value5");
  props.put("prop6", "value6");
  
  ZkNodeProps zkProps = new ZkNodeProps(props);
  byte[] bytes = ZkStateReader.toJSON(zkProps);
  
  ZkNodeProps props2 = ZkNodeProps.load(bytes);
  assertEquals("value1", props2.getStr("prop1"));
  assertEquals("value2", props2.getStr("prop2"));
  assertEquals("value3", props2.getStr("prop3"));
  assertEquals("value4", props2.getStr("prop4"));
  assertEquals("value5", props2.getStr("prop5"));
  assertEquals("value6", props2.getStr("prop6"));
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:ZkNodePropsTest.java

示例3: testStoreAndRead

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
@Test
public void testStoreAndRead() throws Exception {
  Map<String,DocCollection> collectionStates = new HashMap<>();
  Set<String> liveNodes = new HashSet<>();
  liveNodes.add("node1");
  liveNodes.add("node2");
  
  Map<String,Slice> slices = new HashMap<>();
  Map<String,Replica> sliceToProps = new HashMap<>();
  Map<String,Object> props = new HashMap<>();

  props.put("prop1", "value");
  props.put("prop2", "value2");
  Replica replica = new Replica("node1", props);
  sliceToProps.put("node1", replica);
  Slice slice = new Slice("shard1", sliceToProps, null);
  slices.put("shard1", slice);
  Slice slice2 = new Slice("shard2", sliceToProps, null);
  slices.put("shard2", slice2);
  collectionStates.put("collection1", new DocCollection("collection1", slices, null, DocRouter.DEFAULT));
  collectionStates.put("collection2", new DocCollection("collection2", slices, null, DocRouter.DEFAULT));
  ZkStateReader zkStateReaderMock = getMockZkStateReader(collectionStates.keySet());
  
  ClusterState clusterState = new ClusterState(-1,liveNodes, collectionStates);
  byte[] bytes = ZkStateReader.toJSON(clusterState);
  // System.out.println("#################### " + new String(bytes));
  ClusterState loadedClusterState = ClusterState.load(-1, bytes, liveNodes);
  
  assertEquals("Provided liveNodes not used properly", 2, loadedClusterState
      .getLiveNodes().size());
  assertEquals("No collections found", 2, loadedClusterState.getCollections().size());
  assertEquals("Poperties not copied properly", replica.getStr("prop1"), loadedClusterState.getSlice("collection1", "shard1").getReplicasMap().get("node1").getStr("prop1"));
  assertEquals("Poperties not copied properly", replica.getStr("prop2"), loadedClusterState.getSlice("collection1", "shard1").getReplicasMap().get("node1").getStr("prop2"));

  loadedClusterState = ClusterState.load(-1, new byte[0], liveNodes);
  
  assertEquals("Provided liveNodes not used properly", 2, loadedClusterState
      .getLiveNodes().size());
  assertEquals("Should not have collections", 0, loadedClusterState.getCollections().size());

  loadedClusterState = ClusterState.load(-1, (byte[])null, liveNodes);
  
  assertEquals("Provided liveNodes not used properly", 2, loadedClusterState
      .getLiveNodes().size());
  assertEquals("Should not have collections", 0, loadedClusterState.getCollections().size());
}
 
开发者ID:europeana,项目名称:search,代码行数:47,代码来源:ClusterStateTest.java


注:本文中的org.apache.solr.common.cloud.ZkStateReader.toJSON方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。