View Javadoc

1   package org.apache.helix;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.concurrent.ExecutorService;
23  import java.util.concurrent.Executors;
24  
25  import org.apache.helix.BaseDataAccessor;
26  import org.apache.helix.GroupCommit;
27  import org.apache.helix.ZNRecord;
28  
29  
30  public class TestGroupCommit
31  {
32    // @Test
33    public void testGroupCommit() throws InterruptedException
34    {
35      final BaseDataAccessor<ZNRecord> accessor = new Mocks.MockBaseDataAccessor();
36      final GroupCommit commit = new GroupCommit();
37      ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(400);
38      for (int i = 0; i < 2400; i++)
39      {
40        Runnable runnable = new MyClass(accessor, commit, i);
41        newFixedThreadPool.submit(runnable);
42      }
43      Thread.sleep(10000);
44      System.out.println(accessor.get("test", null, 0));
45      System.out.println(accessor.get("test", null, 0).getSimpleFields().size());
46    }
47  
48  }
49  
50  class MyClass implements Runnable
51  {
52    private final BaseDataAccessor<ZNRecord> store;
53    private final GroupCommit                commit;
54    private final int                        i;
55  
56    public MyClass(BaseDataAccessor<ZNRecord> store, GroupCommit commit, int i)
57    {
58      this.store = store;
59      this.commit = commit;
60      this.i = i;
61    }
62  
63    @Override
64    public void run()
65    {
66      // System.out.println("START " + System.currentTimeMillis() + " --"
67      // + Thread.currentThread().getId());
68      ZNRecord znRecord = new ZNRecord("test");
69      znRecord.setSimpleField("test_id" + i, "" + i);
70      commit.commit(store, 0, "test", znRecord);
71      store.get("test", null, 0).getSimpleField("");
72      // System.out.println("END " + System.currentTimeMillis() + " --"
73      // + Thread.currentThread().getId());
74    }
75  
76  }