@Before
  public void setup() throws IOException {
    byte[] bytes1 = {(byte) 'A', (byte) 'B'};
    byte[] bytes2 = {(byte) 'C', (byte) 'D'};
    List<StoreDefinition> stores = ClusterTestUtils.getZZZ322StoreDefs("memory");
    StoreDefinition storeDef = stores.get(0);
    cluster = ClusterTestUtils.getZZZCluster();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setBootstrapUrls(cluster.getNodeById(0).getSocketUrl().toString());
    clientConfig.getZoneAffinity().setEnableGetOpZoneAffinity(true);
    clientConfig.setClientZoneId(clientZoneId);
    SocketStoreClientFactory socketStoreClientFactory = new SocketStoreClientFactory(clientConfig);
    for (Integer nodeId : cluster.getNodeIds()) {
      SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 1024);
      VoldemortConfig config =
          ServerTestUtils.createServerConfigWithDefs(
              true,
              nodeId,
              TestUtils.createTempDir().getAbsolutePath(),
              cluster,
              stores,
              new Properties());
      VoldemortServer vs =
          ServerTestUtils.startVoldemortServer(socketStoreFactory, config, cluster);
      vservers.put(nodeId, vs);
      socketStoreFactories.put(nodeId, socketStoreFactory);
      Store<ByteArray, byte[], byte[]> store =
          vs.getStoreRepository().getLocalStore(storeDef.getName());
      Node node = cluster.getNodeById(nodeId);

      VectorClock version1 = new VectorClock();
      version1.incrementVersion(0, System.currentTimeMillis());
      VectorClock version2 = version1.incremented(0, System.currentTimeMillis());

      if (node.getZoneId() == clientZoneId) {
        store.put(new ByteArray(bytes1), new Versioned<byte[]>(bytes1, version1), null);
      } else {
        store.put(new ByteArray(bytes1), new Versioned<byte[]>(bytes2, version2), null);
      }
    }

    client = socketStoreClientFactory.getRawStore(storeDef.getName(), null);
  }
예제 #2
0
  @Before
  public void setUp() throws Exception {
    cluster = getNineNodeCluster();
    storeDef =
        getStoreDef(
            STORE_NAME,
            REPLICATION_FACTOR,
            P_READS,
            R_READS,
            P_WRITES,
            R_WRITES,
            RoutingStrategyType.CONSISTENT_STRATEGY);
    for (Node node : cluster.getNodes()) {
      VoldemortException e = new UnreachableStoreException("Node down");

      InMemoryStorageEngine<ByteArray, byte[], byte[]> storageEngine =
          new InMemoryStorageEngine<ByteArray, byte[], byte[]>(STORE_NAME);
      LoggingStore<ByteArray, byte[], byte[]> loggingStore =
          new LoggingStore<ByteArray, byte[], byte[]>(storageEngine);
      subStores.put(
          node.getId(),
          new ForceFailStore<ByteArray, byte[], byte[]>(loggingStore, e, node.getId()));
    }

    setFailureDetector(subStores);

    for (Node node : cluster.getNodes()) {
      int nodeId = node.getId();
      StoreRepository storeRepo = new StoreRepository();
      storeRepo.addLocalStore(subStores.get(nodeId));

      for (int i = 0; i < NUM_NODES_TOTAL; i++) storeRepo.addNodeStore(i, subStores.get(i));

      SlopStorageEngine slopStorageEngine =
          new SlopStorageEngine(
              new InMemoryStorageEngine<ByteArray, byte[], byte[]>(SLOP_STORE_NAME), cluster);
      StorageEngine<ByteArray, Slop, byte[]> storageEngine = slopStorageEngine.asSlopStore();
      storeRepo.setSlopStore(slopStorageEngine);
      slopStores.put(nodeId, storageEngine);

      MetadataStore metadataStore =
          ServerTestUtils.createMetadataStore(cluster, Lists.newArrayList(storeDef));
      StreamingSlopPusherJob pusher =
          new StreamingSlopPusherJob(
              storeRepo,
              metadataStore,
              failureDetector,
              ServerTestUtils.createServerConfigWithDefs(
                  false,
                  nodeId,
                  TestUtils.createTempDir().getAbsolutePath(),
                  cluster,
                  Lists.newArrayList(storeDef),
                  new Properties()));
      slopPusherJobs.add(pusher);
    }

    routedStoreThreadPool = Executors.newFixedThreadPool(NUM_THREADS);
    routedStoreFactory = new RoutedStoreFactory(true, routedStoreThreadPool, 1000L);
    strategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef, cluster);
    Map<Integer, NonblockingStore> nonblockingStores = Maps.newHashMap();

    for (Map.Entry<Integer, Store<ByteArray, byte[], byte[]>> entry : subStores.entrySet())
      nonblockingStores.put(
          entry.getKey(), routedStoreFactory.toNonblockingStore(entry.getValue()));

    store =
        routedStoreFactory.create(
            cluster,
            storeDef,
            subStores,
            nonblockingStores,
            slopStores,
            false,
            Zone.DEFAULT_ZONE_ID,
            failureDetector);

    generateData();
  }