text:
package com.example.administrator.aviation.ui.activity.domflightcheck;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.aviation.R;
import com.example.administrator.aviation.http.HttpCommons;
import com.example.administrator.aviation.http.HttpRoot;
import com.example.administrator.aviation.model.domjcgrbb.FlightAWBPlanInfo;
import com.example.administrator.aviation.model.domjcgrbb.FlightCheckInfo;
import com.example.administrator.aviation.model.domjcgrbb.FlightPlanInfo;
import com.example.administrator.aviation.model.domjcgrbb.PrepareceFlightAWBPlanInfo;
import com.example.administrator.aviation.ui.base.NavBar;

import org.ksoap2.serialization.SoapObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 订舱确认界面
 */

public class DomFlightCheckSureActivity extends Activity implements View.OnClickListener{
    @BindView(R.id.flight_check_sure_nodata_tv)
    TextView flightCheckSureNodataTv;
    @BindView(R.id.flight_check_sure_lv)
    ListView flightCheckSureLv;
    @BindView(R.id.zhixian_pb)
    ProgressBar zhixianPb;
    @BindView(R.id.flight_check_sure_btn)
    Button flightCheckSureBtn;
    @BindView(R.id.flight_check_cancel_btn)
    Button flightCheckCancelBtn;

    private FlightCheckInfo flightCheckInfo;
    private List<FlightAWBPlanInfo> flightAWBPlanInfoList;
    private MyAWBPlanAdapter myAWBPlanAdapter;

    private Map<Integer, FlightPlanInfo> choseMap;

    private String xml;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_appintflight_check_sure);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        NavBar navBar = new NavBar(this);
        navBar.setTitle("订舱确认");
        navBar.hideRight();

        // 按钮点击事件
        flightCheckSureBtn.setOnClickListener(this);
        flightCheckCancelBtn.setOnClickListener(this);

        choseMap = new HashMap<>();

        // 首次进入得到数据
        showData();

        // 订舱确认列表点击到详情页
        flightCheckSureLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                Intent intent = new Intent(DomFlightCheckSureActivity.this, DomFlightCheckSureDetailActivity.class);
                FlightAWBPlanInfo flightAWBPlanInfo = flightAWBPlanInfoList.get(position);
                Bundle bundle = new Bundle();
                bundle.putSerializable("checksure", flightAWBPlanInfo);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            // 订舱确认
            case R.id.flight_check_sure_btn:
                Set<Integer> keys = choseMap.keySet();
                for (Integer key:keys) {
                    FlightPlanInfo flightPlanInfo = choseMap.get(key);
                    String fdate = flightCheckInfo.getFDate();
                    String fno = flightCheckInfo.getFno();
                    String istrue = "1";
                    xml = getsureCancelXml(flightPlanInfo, fdate, fno, istrue);
                    if (choseMap.isEmpty()) {
                        Toast.makeText(this, "没有选择", Toast.LENGTH_SHORT).show();
                    } else {
                        Map<String, String> checkSureMap = new HashMap<>();
                        checkSureMap.put("awbXml", xml);
                        checkSureMap.put("ErrString", "");
                        HttpRoot.getInstance().requstAync(DomFlightCheckSureActivity.this, HttpCommons.CGO_DOM_EXPORT_FLIGHT_PLAN_CHECK_NAME,
                                HttpCommons.CGO_DOM_EXPORT_FLIGHT_PLAN_CHECK_ACTION, checkSureMap, new HttpRoot.CallBack() {
                                    @Override
                                    public void onSucess(Object result) {
                                        SoapObject soapObject = (SoapObject) result;
                                        String a = soapObject.getProperty(0).toString();
                                        Toast.makeText(DomFlightCheckSureActivity.this, a, Toast.LENGTH_SHORT).show();
                                        showData();
                                    }

                                    @Override
                                    public void onFailed(String message) {

                                    }

                                    @Override
                                    public void onError() {

                                    }
                                });
                    }
                }
                break;

            // 订舱取消
            case R.id.flight_check_cancel_btn:
                Set<Integer> keyes = choseMap.keySet();
                for (Integer key:keyes) {
                    FlightPlanInfo flightPlanInfo = choseMap.get(key);
                    String fdate = flightCheckInfo.getFDate();
                    String fno = flightCheckInfo.getFno();
                    String isTru = "0";
                    xml = getsureCancelXml(flightPlanInfo, fdate, fno, isTru);
                    if (choseMap.isEmpty()) {
                        Toast.makeText(this, "没有选择", Toast.LENGTH_SHORT).show();
                    } else {
                        Map<String, String> checkSureMap = new HashMap<>();
                        checkSureMap.put("awbXml", xml);
                        checkSureMap.put("ErrString", "");
                        HttpRoot.getInstance().requstAync(DomFlightCheckSureActivity.this, HttpCommons.CGO_DOM_EXPORT_FLIGHT_PLAN_CHECK_NAME,
                                HttpCommons.CGO_DOM_EXPORT_FLIGHT_PLAN_CHECK_ACTION, checkSureMap, new HttpRoot.CallBack() {
                                    @Override
                                    public void onSucess(Object result) {
                                        SoapObject soapObject = (SoapObject) result;
                                        String a = soapObject.getProperty(0).toString();
                                        Toast.makeText(DomFlightCheckSureActivity.this, a, Toast.LENGTH_SHORT).show();
                                        showData();
                                    }

                                    @Override
                                    public void onFailed(String message) {

                                    }

                                    @Override
                                    public void onError() {

                                    }
                                });
                    }
                }
                break;

            default:
                break;
        }
    }

    // 适配器
    private class MyAWBPlanAdapter extends BaseAdapter {
        private Context context;
        private List<FlightAWBPlanInfo> flightAWBPlanInfoList;
        public MyAWBPlanAdapter(Context context, List<FlightAWBPlanInfo> flightAWBPlanInfoList) {
            this.context = context;
            this.flightAWBPlanInfoList = flightAWBPlanInfoList;
        }

        @Override
        public int getCount() {
            return flightAWBPlanInfoList.size();
        }

        @Override
        public FlightAWBPlanInfo getItem(int position) {
            return flightAWBPlanInfoList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup viewGroup) {
            final FlightAWBPlanInfo item = getItem(position);
            ViewHolder viewHolder;
            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(R.layout.flight_check_sure_item, viewGroup, false);
                viewHolder = new ViewHolder();
                viewHolder.planCb = (CheckBox) convertView.findViewById(R.id.flight_plan_checkbox);
                viewHolder.mawbTv = (TextView) convertView.findViewById(R.id.flight_plan_mawb_tv);
                viewHolder.nameTv = (TextView) convertView.findViewById(R.id.flight_plan_name_tv);
                viewHolder.pcTv = (TextView) convertView.findViewById(R.id.flight_plan_pc_tv);
                viewHolder.weightTv = (TextView) convertView.findViewById(R.id.flight_plan_weight_tv);
                viewHolder.volumeTv = (TextView) convertView.findViewById(R.id.flight_plan_volume_tv);
                viewHolder.userTv = (TextView) convertView.findViewById(R.id.flight_plan_user_tv);
                viewHolder.timeTv = (TextView) convertView.findViewById(R.id.flight_plan_time_tv);
                viewHolder.sureStateTv = (TextView) convertView.findViewById(R.id.flight_plan_surestate_tv);
                viewHolder.showLy = (LinearLayout) convertView.findViewById(R.id.awb_linear_layout);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            String mawb = flightAWBPlanInfoList.get(position).getMawb();
            if (mawb != null && !mawb.equals("")) {
                viewHolder.mawbTv.setText(mawb);
            } else {
                viewHolder.mawbTv.setText("");
            }
            String name = flightAWBPlanInfoList.get(position).getAgentName();
            if (name != null && !name.equals("")) {
                viewHolder.nameTv.setText(name);
            } else {
                viewHolder.nameTv.setText("");
            }
            String pc = flightAWBPlanInfoList.get(position).getPC();
            if (pc != null && !pc.equals("")) {
                viewHolder.pcTv.setText(pc);
            } else {
                viewHolder.pcTv.setText("");
            }
            String weight = flightAWBPlanInfoList.get(position).getWeight();
            if (weight != null && !weight.equals("")) {
                viewHolder.weightTv.setText(weight);
            } else {
                viewHolder.weightTv.setText("");
            }
            String volume = flightAWBPlanInfoList.get(position).getVolume();
            if (volume != null && !volume.equals("")) {
                viewHolder.volumeTv.setText(volume);
            } else {
                viewHolder.volumeTv.setText("");
            }
            String user = flightAWBPlanInfoList.get(position).getCheckID();
            if (user != null && !user.equals("")) {
                viewHolder.userTv.setText(user);
            } else {
                viewHolder.userTv.setText("");
            }
            String time = flightAWBPlanInfoList.get(position).getCheckTime();
            if (time != null && !time.equals("")) {
                viewHolder.timeTv.setText(time);
            } else {
                viewHolder.timeTv.setText("");
            }
            String sureState = flightAWBPlanInfoList.get(position).getFlightChecked();
            if (sureState != null && !sureState.equals("")) {
                viewHolder.sureStateTv.setText(sureState);
                if (sureState.equals("1")) {
                    viewHolder.showLy.setBackgroundColor(Color.parseColor("#fbd0cf"));
                }
            } else {
                viewHolder.sureStateTv.setText("");
            }

            viewHolder.planCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                    if (b) {
                        FlightPlanInfo info = new FlightPlanInfo(item.getFDate(),item.getFno(),item.getFlightChecked(),item.getMawb());
                        choseMap.put(position, info);
                    } else {
                        choseMap.remove(position);
                    }
                }
            });
            return convertView;
        }

        class ViewHolder {
            CheckBox planCb;
            TextView mawbTv;
            TextView nameTv;
            TextView pcTv;
            TextView weightTv;
            TextView volumeTv;
            TextView userTv;
            TextView timeTv;
            TextView sureStateTv;
            LinearLayout showLy;
        }
    }

    // 请求数据信息
    private String getXml(String fdate, String fno, String jTg, String fDest) {
        return "<GNCAWBPlan>"
                + "<FDate>" + fdate + "</FDate>"
                + "<Fno>" + fno + "</Fno>"
                + " <JTZ>" + jTg + "</JTZ>"
                + "  <FDest>" + fDest + "</FDest>"
                + "</GNCAWBPlan>";
    }

    // 订舱确认与取消订舱xml
    private String getsureCancelXml(FlightPlanInfo flightPlanInfo, String fdate, String fno, String isTrue) {
        String pre = "<GNCAWBPlan>";
        String after ="</GNCAWBPlan>";
        String result = pre;
            result += "<FDate>"+fdate+"</FDate>"
                    +"<Fno>" + fno + "</Fno>"
                    + "<FlightChecked>"+isTrue+"</FlightChecked>"
                    +"<Mawb>" + flightPlanInfo.getMawb() + "</Mawb>";
        result = result+after;
        return result;
    }

    // 展示订舱确认数据界面
    private void showData() {
        // 得到待确认航班计划列表传递过来的数据
        flightCheckInfo = (FlightCheckInfo) getIntent().getSerializableExtra("domflightsure");
        String fDate = flightCheckInfo.getFDate();
        String fno = flightCheckInfo.getFno();
        String jTg = flightCheckInfo.getJTZ();
        String fDest = flightCheckInfo.getFDest();
        String xml = getXml(fDate, fno, jTg, fDest);
        // 解析数据
        Map<String, String> params = new HashMap<>();
        params.put("awbXml", xml);
        params.put("ErrString", "");
        HttpRoot.getInstance().requstAync(DomFlightCheckSureActivity.this, HttpCommons.CGO_GET_DOM_FLIGHT_AWB_PLAN_NAME,
                HttpCommons.CGO_GET_DOM_FLIGHT_AWB_PLAN_NACTION, params, new HttpRoot.CallBack() {
                    @Override
                    public void onSucess(Object result) {
                        zhixianPb.setVisibility(View.VISIBLE);
                        SoapObject object = (SoapObject) result;
                        String awbXml = object.getProperty(0).toString();
                        flightAWBPlanInfoList = PrepareceFlightAWBPlanInfo.parseFlightAWBPlanInfoXml(awbXml);
                        assert flightAWBPlanInfoList != null;
                        if (flightAWBPlanInfoList.size() >= 1) {
                            myAWBPlanAdapter = new MyAWBPlanAdapter(DomFlightCheckSureActivity.this, flightAWBPlanInfoList);
                            flightCheckSureLv.setAdapter(myAWBPlanAdapter);
                            zhixianPb.setVisibility(View.GONE);
                        } else {
                            zhixianPb.setVisibility(View.GONE);
                            flightCheckSureNodataTv.setVisibility(View.VISIBLE);
                        }

                    }

                    @Override
                    public void onFailed(String message) {
                        zhixianPb.setVisibility(View.GONE);
                    }

                    @Override
                    public void onError() {
                        zhixianPb.setVisibility(View.GONE);
                    }
                });
    }
}


text:
package com.gemstone.gemfire.cache.hdfs.internal.hoplog;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;

import io.snappydata.test.dunit.AvailablePortHelper;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.MiniDFSCluster.Builder;
import org.apache.hadoop.hdfs.MiniDFSNNTopology;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider;

import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.hdfs.HDFSIOException;
import com.gemstone.gemfire.cache.hdfs.HDFSStore.HDFSCompactionConfig;
import com.gemstone.gemfire.cache.hdfs.HDFSStoreMutator;
import com.gemstone.gemfire.cache.hdfs.internal.HDFSStoreImpl;
import com.gemstone.gemfire.cache.hdfs.internal.PersistedEventImpl;
import com.gemstone.gemfire.cache.hdfs.internal.SortedHoplogPersistedEvent;
import com.gemstone.gemfire.cache.hdfs.internal.hoplog.AbstractHoplogOrganizer.HoplogComparator;
import com.gemstone.gemfire.cache.hdfs.internal.hoplog.HDFSRegionDirector.HdfsRegionManager;
import com.gemstone.gemfire.cache.hdfs.internal.hoplog.HoplogOrganizer.Compactor;
import com.gemstone.gemfire.cache.hdfs.internal.hoplog.TieredCompactionJUnitTest.TestHoplog;
import com.gemstone.gemfire.cache.hdfs.internal.hoplog.mapreduce.HoplogUtil;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.TestUtils;
import com.gemstone.gemfire.internal.cache.TestUtils.ExpectedException;
import com.gemstone.gemfire.internal.cache.persistence.soplog.TrackedReference;
import com.gemstone.gemfire.internal.util.BlobHelper;
public class HdfsSortedOplogOrganizerJUnitTest extends BaseHoplogTestCase {
  /**
   * Tests flush operation
   */
  public void testFlush() throws Exception {
    int count = 10;
    int bucketId = (int) System.nanoTime();
    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, bucketId);

    // flush and create hoplog
    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    for (int i = 0; i < count; i++) {
      items.add(new TestEvent(("key-" + i), ("value-" + System.nanoTime())));
    }
    organizer.flush(items.iterator(), count);

    // check file existence in bucket directory
    FileStatus[] hoplogs = getBucketHoplogs(getName() + "/" + bucketId,
                      HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);

    // only one hoplog should exists
    assertEquals(1, hoplogs.length);

    assertEquals(count, organizer.sizeEstimate());
    assertEquals(0, stats.getActiveReaderCount());
  }

  /**
   * Tests reads from a set of hoplogs containing both valid and stale KVs
   */
  public void testReopen() throws Exception {
    int bucketId = (int) System.nanoTime();
    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, bucketId);

    // flush and create hoplog
    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    for (int i = 0; i < 100; i++) {
      items.add(new TestEvent("" + i, ("1-1")));
    }
    organizer.flush(items.iterator(), items.size());

    Hoplog hoplog = organizer.getSortedOplogs().iterator().next().get();
    byte[] keyBytes1 = BlobHelper.serializeToBlob("1");
    hoplog.close();

    for (int i = 0; i < 10; i++) {
      Path path = new Path(testDataDir, getName() + "/" + bucketId + "/" + hoplog.getFileName());
      HFileSortedOplog oplog = new HFileSortedOplog(hdfsStore, path, blockCache, stats, storeStats);
      oplog.getReader().read(keyBytes1);
      oplog.close(false);
    }
  }

  /**
   * Tests reads from a set of hoplogs containing both valid and stale KVs
   */
  public void testRead() throws Exception {
    doRead(regionManager);
  }

  public void testNewReaderWithNameNodeHA() throws Exception {
    deleteMiniClusterDir();
    int nn1port = AvailablePortHelper.getRandomAvailableTCPPort();
    int nn2port = AvailablePortHelper.getRandomAvailableTCPPort();

    MiniDFSCluster cluster = initMiniHACluster(nn1port, nn2port);
    initClientHAConf(nn1port, nn2port);

    HDFSStoreImpl store1 = (HDFSStoreImpl) hsf.create("Store-1");
    regionfactory.setHDFSStoreName(store1.getName());
    Region<Object, Object> region1 = regionfactory.create("region-1");
    HdfsRegionManager regionManager1 = ((LocalRegion)region1).getHdfsRegionManager();

    HoplogOrganizer<SortedHoplogPersistedEvent> organizer = doRead(regionManager1);
    organizer.close();

    TestUtils.addExpectedException("java.io.EOFException");
    NameNode nnode2 = cluster.getNameNode(1);
    assertTrue(nnode2.isStandbyState());
    cluster.shutdownNameNode(0);
    cluster.transitionToActive(1);
    assertFalse(nnode2.isStandbyState());

    organizer = new HdfsSortedOplogOrganizer(regionManager1, 0);
    byte[] keyBytes1 = BlobHelper.serializeToBlob("1");
    byte[] keyBytes3 = BlobHelper.serializeToBlob("3");
    byte[] keyBytes4 = BlobHelper.serializeToBlob("4");
    assertEquals("2-1", organizer.read(keyBytes1).getValue());
    assertEquals("3-3", organizer.read(keyBytes3).getValue());
    assertEquals("1-4", organizer.read(keyBytes4).getValue());
    TestUtils.removeExpectedException("java.io.EOFException");

    region1.destroyRegion();
    store1.destroy();
    cluster.shutdown();
    FileUtils.deleteDirectory(new File("hdfs-test-cluster"));
  }

  public void testActiveReaderWithNameNodeHA() throws Exception {
    deleteMiniClusterDir();
    int nn1port = AvailablePortHelper.getRandomAvailableTCPPort();
    int nn2port = AvailablePortHelper.getRandomAvailableTCPPort();

    MiniDFSCluster cluster = initMiniHACluster(nn1port, nn2port);
    initClientHAConf(nn1port, nn2port);

    HDFSStoreImpl store1 = (HDFSStoreImpl) hsf.create("Store-1");
    regionfactory.setHDFSStoreName(store1.getName());
    Region<Object, Object> region1 = regionfactory.create("region-1");
    HdfsRegionManager regionManager1 = ((LocalRegion)region1).getHdfsRegionManager();

    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager1, 0);
    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    for (int i = 100000; i < 101000; i++) {
      items.add(new TestEvent(("" + i), (i + " some string " + i)));
    }
    organizer.flush(items.iterator(), items.size());
    organizer.getSortedOplogs().get(0).get().getReader();

    TestUtils.addExpectedException("java.io.EOFException");
    NameNode nnode2 = cluster.getNameNode(1);
    assertTrue(nnode2.isStandbyState());
    cluster.shutdownNameNode(0);
    cluster.transitionToActive(1);
    assertFalse(nnode2.isStandbyState());

    for (int i = 100000; i < 100500; i++) {
      byte[] keyBytes1 = BlobHelper.serializeToBlob("" + i);
      assertEquals(i + " some string " + i, organizer.read(keyBytes1).getValue());
    }
    TestUtils.removeExpectedException("java.io.EOFException");

    region1.destroyRegion();
    store1.destroy();
    cluster.shutdown();
    FileUtils.deleteDirectory(new File("hdfs-test-cluster"));
  }

  public void testFlushWithNameNodeHA() throws Exception {
    deleteMiniClusterDir();
    int nn1port = AvailablePortHelper.getRandomAvailableTCPPort();
    int nn2port = AvailablePortHelper.getRandomAvailableTCPPort();

    MiniDFSCluster cluster = initMiniHACluster(nn1port, nn2port);

    initClientHAConf(nn1port, nn2port);
    HDFSStoreImpl store1 = (HDFSStoreImpl) hsf.create("Store-1");

    regionfactory.setHDFSStoreName(store1.getName());
    Region<Object, Object> region1 = regionfactory.create("region-1");
    HdfsRegionManager regionManager1 = ((LocalRegion)region1).getHdfsRegionManager();

    HoplogOrganizer<SortedHoplogPersistedEvent> organizer = new HdfsSortedOplogOrganizer(regionManager1, 0);
    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    items.add(new TestEvent(("1"), ("1-1")));
    organizer.flush(items.iterator(), items.size());

    TestUtils.addExpectedException("java.io.EOFException");
    NameNode nnode2 = cluster.getNameNode(1);
    assertTrue(nnode2.isStandbyState());
    cluster.shutdownNameNode(0);
    cluster.transitionToActive(1);
    assertFalse(nnode2.isStandbyState());

    items.add(new TestEvent(("4"), ("1-4")));
    organizer.flush(items.iterator(), items.size());
    byte[] keyBytes1 = BlobHelper.serializeToBlob("1");
    byte[] keyBytes4 = BlobHelper.serializeToBlob("4");
    assertEquals("1-1", organizer.read(keyBytes1).getValue());
    assertEquals("1-4", organizer.read(keyBytes4).getValue());
    TestUtils.removeExpectedException("java.io.EOFException");

    region1.destroyRegion();
    store1.destroy();
    cluster.shutdown();
    FileUtils.deleteDirectory(new File("hdfs-test-cluster"));
  }

  private void initClientHAConf(int nn1port, int nn2port) throws Exception {
    hsf.setHomeDir("test-case");
    hsf.setNameNodeURL("hdfs://ns1");
    File confFile = new File(getName());
    String conf = "<configuration>\n             "
        + "  <property>\n                                    "
        + "    <name>dfs.nameservices</name>\n               "
        + "    <value>ns1</value>\n                          "
        + "  </property>\n                                   "
        + "  <property>\n                                    "
        + "    <name>dfs.ha.namenodes.ns1</name>\n           "
        + "    <value>nn1,nn2</value>\n                      "
        + "  </property>\n                                   "
        + "  <property>\n                                    "
        + "    <name>dfs.namenode.rpc-address.ns1.nn1</name>\n"
        + "    <value>hdfs://127.0.0.1:" + nn1port + "</value>\n"
        + "  </property>\n                                   "
        + "  <property>\n                                    "
        + "    <name>dfs.namenode.rpc-address.ns1.nn2</name>\n"
        + "    <value>hdfs://127.0.0.1:" + nn2port + "</value>\n"
        + "  </property>\n                                   "
        + "  <property>\n                                    "
        + "    <name>dfs.client.failover.proxy.provider.ns1</name>\n"
        + "    <value>" + ConfiguredFailoverProxyProvider.class.getName() + "</value>\n"
        + "  </property>\n                                   "
        + "</configuration>";
    setConfigFile(hsf, confFile, conf);
  }

  private MiniDFSCluster initMiniHACluster(int nn1port, int nn2port)
      throws IOException {
    Configuration confForMiniDFS = new Configuration();

    Builder builder = new MiniDFSCluster.Builder(confForMiniDFS)
    .nnTopology(new MiniDFSNNTopology()
    .addNameservice(new MiniDFSNNTopology.NSConf("ns1")
    .addNN(new MiniDFSNNTopology.NNConf("nn1").setIpcPort(nn1port))
    .addNN(new MiniDFSNNTopology.NNConf("nn2").setIpcPort(nn2port))
        ))
        .numDataNodes(1);

    MiniDFSCluster cluster = builder.build();
    cluster.waitActive();

    NameNode nnode1 = cluster.getNameNode(0);
    assertTrue(nnode1.isStandbyState());
    NameNode nnode2 = cluster.getNameNode(1);
    assertTrue(nnode2.isStandbyState());

    cluster.transitionToActive(0);
    assertFalse(nnode1.isStandbyState());
    return cluster;
  }

  public HoplogOrganizer<SortedHoplogPersistedEvent> doRead(HdfsRegionManager rm) throws Exception {
    HoplogOrganizer<SortedHoplogPersistedEvent> organizer = new HdfsSortedOplogOrganizer(rm, 0);

    // flush and create hoplog
    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    items.add(new TestEvent(("1"), ("1-1")));
    items.add(new TestEvent(("4"), ("1-4")));
    organizer.flush(items.iterator(), items.size());

    items.clear();
    items.add(new TestEvent(("1"), ("2-1")));
    items.add(new TestEvent(("3"), ("2-3")));
    organizer.flush(items.iterator(), items.size());

    items.clear();
    items.add(new TestEvent(("3"), ("3-3")));
    items.add(new TestEvent(("5"), ("3-5")));
    organizer.flush(items.iterator(), items.size());

    // check file existence in bucket directory
    FileStatus[] hoplogs = getBucketHoplogs(rm.getStore().getFileSystem(),
        rm.getRegionFolder() + "/" + 0,
        HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);

    // expect 3 files are 3 flushes
    assertEquals(3, hoplogs.length);
    byte[] keyBytes1 = BlobHelper.serializeToBlob("1");
    byte[] keyBytes3 = BlobHelper.serializeToBlob("3");
    byte[] keyBytes4 = BlobHelper.serializeToBlob("4");
    // expect key 1 from hoplog 2
    assertEquals("2-1", organizer.read(keyBytes1).getValue());
    // expect key 3 from hoplog 3
    assertEquals("3-3", organizer.read(keyBytes3).getValue());
    // expect key 4 from hoplog 1
    assertEquals("1-4", organizer.read(keyBytes4).getValue());
    return organizer;
  }

  /**
   * Tests bucket organizer initialization during startup. Existing hoplogs should identified and
   * returned
   */
  public void testHoplogIdentification() throws Exception {
    // create one empty file and one directories in bucket directory
    Path bucketPath = new Path(testDataDir, getName() + "/0");
    FileSystem fs = hdfsStore.getFileSystem();
    fs.createNewFile(new Path(bucketPath, "temp_file"));
    fs.mkdirs(new Path(bucketPath, "temp_dir"));

    // create 2 hoplogs files each of type flush, minor and major hoplog
    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, 0);
    String[] extensions = { HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        HdfsSortedOplogOrganizer.MINOR_HOPLOG_EXTENSION,
        HdfsSortedOplogOrganizer.MINOR_HOPLOG_EXTENSION,
        HdfsSortedOplogOrganizer.MAJOR_HOPLOG_EXTENSION,
        HdfsSortedOplogOrganizer.MAJOR_HOPLOG_EXTENSION};
    for (String string : extensions) {
      Hoplog oplog = organizer.getTmpSortedOplog(null, string);
      createHoplog(0, oplog);
      organizer.makeLegitimate(oplog);
    }

    // create a temp hoplog
    Hoplog oplog = organizer.getTmpSortedOplog(null, HdfsSortedOplogOrganizer.MAJOR_HOPLOG_EXTENSION);
    createHoplog(0, oplog);

    // bucket directory should have 6 hoplogs, 1 temp log, 1 misc file and 1 directory
    FileStatus[] results = fs.listStatus(bucketPath);
    assertEquals(9, results.length);

    // only two are hoplogs
    List<Hoplog> list = organizer.identifyAndLoadSortedOplogs(true);
    assertEquals(6, list.size());
  }

  public void testExpiryMarkerIdentification() throws Exception {
    // epxired hoplogs from the list below should be deleted
    String[] files = {
        "0-1-1231" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        "0-2-1232" + AbstractHoplogOrganizer.MAJOR_HOPLOG_EXTENSION,
        "0-3-1233" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION,
        "0-4-1234" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION,
        "0-5-1235" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION };

    Path bucketPath = new Path(testDataDir, getName() + "/0");
    FileSystem fs = hdfsStore.getFileSystem();
    for (String file : files) {
      Hoplog oplog = new HFileSortedOplog(hdfsStore, new Path(bucketPath, file),
          blockCache, stats, storeStats);
      createHoplog(10, oplog);
    }

    String marker1 = "0-4-1234"
        + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION
        + AbstractHoplogOrganizer.EXPIRED_HOPLOG_EXTENSION;
    fs.createNewFile(new Path(bucketPath, marker1));
    String marker2 = "0-5-1235"
        + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION
        + AbstractHoplogOrganizer.EXPIRED_HOPLOG_EXTENSION;
    fs.createNewFile(new Path(bucketPath, marker2));

    FileStatus[] hoplogs = getBucketHoplogs(getName() + "/0", "");
    assertEquals(7, hoplogs.length);

    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(
        regionManager, 0);

    FileStatus[] markers = organizer.getExpiryMarkers();
    // one hoplog and one exp marker will be deletion targets
    assertEquals(2, markers.length);
    for (FileStatus marker : markers) {
      String name = marker.getPath().getName();
      assertTrue(name.equals(marker1) || name.equals(marker2));
    }
    organizer.close();
  }

  public void testExpiredHoplogCleanup() throws Exception {
    // epxired hoplogs from the list below should be deleted
    String[] files = {
        "0-1-0000" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        "0-1-1111" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        "0-1-1111" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION
        + AbstractHoplogOrganizer.EXPIRED_HOPLOG_EXTENSION,

        "0-2-0000" + AbstractHoplogOrganizer.MAJOR_HOPLOG_EXTENSION,
        "0-2-2222" + AbstractHoplogOrganizer.MAJOR_HOPLOG_EXTENSION,

        "0-3-0000" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION,
        "0-3-3333" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION,
        "0-3-3333" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION
            + AbstractHoplogOrganizer.EXPIRED_HOPLOG_EXTENSION,

        "0-4-4444" + AbstractHoplogOrganizer.MAJOR_HOPLOG_EXTENSION };

    Path bucketPath = new Path(testDataDir, getName() + "/0");
    FileSystem fs = hdfsStore.getFileSystem();
    for (String file : files) {
      if (file.endsWith(AbstractHoplogOrganizer.EXPIRED_HOPLOG_EXTENSION)) {
        fs.createNewFile(new Path(bucketPath, file));
        continue;
      }
      Hoplog oplog = new HFileSortedOplog(hdfsStore, new Path(bucketPath, file),
          blockCache, stats, storeStats);
      createHoplog(10, oplog);
    }

    FileStatus[] hoplogs = getBucketHoplogs(getName() + "/0", "");
    assertEquals(9, hoplogs.length);

    long target = System.currentTimeMillis();
    TimeUnit.SECONDS.sleep(1);

    // all but minor compacted files from below this will not be deleted as it
    // is after target delete time
    files = new String[] {
        "0-4-4444" + AbstractHoplogOrganizer.MAJOR_HOPLOG_EXTENSION
            + AbstractHoplogOrganizer.EXPIRED_HOPLOG_EXTENSION,

        "0-5-5555" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION
            + AbstractHoplogOrganizer.EXPIRED_HOPLOG_EXTENSION,
        "0-5-5555" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION,

        "0-6-6666" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION
    };
    for (String file : files) {
      if (file.endsWith(AbstractHoplogOrganizer.EXPIRED_HOPLOG_EXTENSION)) {
        fs.createNewFile(new Path(bucketPath, file));
        continue;
      }
      Hoplog oplog = new HFileSortedOplog(hdfsStore, new Path(bucketPath, file),
          blockCache, stats, storeStats);
      createHoplog(10, oplog);
    }

    hoplogs = getBucketHoplogs(getName() + "/0", "");
    assertEquals(13, hoplogs.length);
    int hopSize = 0;
    for (FileStatus file : hoplogs) {
      if(file.getLen() > hopSize) {
        hopSize = (int) file.getLen();
      }
    }

    final AtomicInteger behavior = new AtomicInteger(0);
    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, 0) {
      @Override
      protected FileStatus[] getExpiryMarkers() throws IOException {
        if (behavior.get() == 1) {
          ArrayList<FileStatus> markers = new ArrayList<FileStatus>();
          for (FileStatus marker : super.getExpiryMarkers()) {
            markers.add(marker);
          }
          // inject a dummy old expiry marker for major compacted file
          long age = 2 * HDFSCompactionConfig.DEFAULT_MAJOR_COMPACTION_INTERVAL_MINS * 60 * 1000;
          String markerName = "0-2-2222" + AbstractHoplogOrganizer.MAJOR_HOPLOG_EXTENSION + EXPIRED_HOPLOG_EXTENSION;
          FileStatus marker = new FileStatus(0, false, 1, 1024, System.currentTimeMillis() - age, new Path(bucketPath, markerName));
          markers.add(marker);
          return markers.toArray(new FileStatus[markers.size()]);
        }
        return super.getExpiryMarkers();
      }
    };

    List<FileStatus> list = organizer.getOptimizationTargets(target);
    assertEquals(6, list.size());

    behavior.set(1);
    list = organizer.getOptimizationTargets(target);
    assertEquals(8, list.size());

    assertEquals(9 * hopSize, stats.getStoreUsageBytes());
    int count = organizer.deleteExpiredFiles(list);
    assertEquals(8, count);
    assertEquals(5 * hopSize, stats.getStoreUsageBytes());

    List<FileStatus> tmp = new ArrayList<FileStatus>(Arrays.asList(hoplogs));
    for (Iterator<FileStatus> iter = tmp.iterator(); iter.hasNext();) {
      hoplogs = getBucketHoplogs(getName() + "/0", "");
      FileStatus file = iter.next();
      for (FileStatus hoplog : hoplogs) {
        if(hoplog.getPath().getName().startsWith("0-5-5555")) {
          fail("this file should have been deleted" + hoplog.getPath().getName());
        }

        if (hoplog.getPath().getName().equals(file.getPath().getName())) {
          iter.remove();
          break;
        }
      }
    }

    assertEquals(7, tmp.size());
    organizer.close();
  }

  public void testAlterPurgeInterval() throws Exception {
    // epxired hoplogs from the list below should be deleted
    String[] files = {
        "0-1-0000" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        "0-1-1111" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        "0-2-2222" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        "0-4-4444" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION };

    Path bucketPath = new Path(testDataDir, getName() + "/0");
    hdfsStore.getFileSystem();
    for (String file : files) {
      Hoplog oplog = new HFileSortedOplog(hdfsStore, new Path(bucketPath, file),
          blockCache, stats, storeStats);
      createHoplog(10, oplog);
    }

    FileStatus[] hoplogs = getBucketHoplogs(getName() + "/0", "");
    int hopSize = 0;
    for (FileStatus file : hoplogs) {
      if(file.getLen() > hopSize) {
        hopSize = (int) file.getLen();
      }
    }

    final AtomicInteger behavior = new AtomicInteger(0);
    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, 0) {
      @Override
      protected FileStatus[] getExpiryMarkers() throws IOException {
        if (behavior.get() == 1) {
          ArrayList<FileStatus> markers = new ArrayList<FileStatus>();
          // inject dummy old expiry markers
          long age = 120 * 1000; // 120 seconds old
          String markerName = "0-2-2222" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION + EXPIRED_HOPLOG_EXTENSION;
          FileStatus marker = new FileStatus(0, false, 1, 1024, System.currentTimeMillis() - age, new Path(bucketPath, markerName));
          markers.add(marker);
          markerName = "0-4-4444" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION + EXPIRED_HOPLOG_EXTENSION;
          marker = new FileStatus(0, false, 1, 1024, System.currentTimeMillis() - age, new Path(bucketPath, markerName));
          markers.add(marker);
          return markers.toArray(new FileStatus[markers.size()]);
        }
        return super.getExpiryMarkers();
      }
    };

    behavior.set(1);
    int count = organizer.initiateCleanup();
    assertEquals(0, count);

    HDFSStoreMutator mutator = hdfsStore.createHdfsStoreMutator();
    mutator.getCompactionConfigMutator().setOldFilesCleanupIntervalMins(1);
    hdfsStore.alter(mutator);
    count = organizer.initiateCleanup();
    assertEquals(4, count);
  }

  public void testInUseExpiredHoplogCleanup() throws Exception {
    Path bucketPath = new Path(testDataDir, getName() + "/0");
    FileSystem fs = hdfsStore.getFileSystem();

    String[] files = new String[] {
        "0-1-1231" + AbstractHoplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        "0-2-1232" + AbstractHoplogOrganizer.MAJOR_HOPLOG_EXTENSION,
        "0-3-1233" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION,
        "0-4-1234" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION,
        "0-5-1235" + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION };

    for (String file : files) {
      Hoplog oplog = new HFileSortedOplog(hdfsStore, new Path(bucketPath, file),
          blockCache, stats, storeStats);
      createHoplog(10, oplog);
    }

    final HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(
        regionManager, 0);
    List<TrackedReference<Hoplog>> hopRefs = organizer.getSortedOplogs();
    assertEquals(files.length, hopRefs.size());

    // this is expiry marker for one of the files that will be compacted below.
    // While compaction is going on file deletion should not happen
    files = new String[] { "0-5-1235"
        + AbstractHoplogOrganizer.MINOR_HOPLOG_EXTENSION
        + AbstractHoplogOrganizer.EXPIRED_HOPLOG_EXTENSION };

    for (String file : files) {
      fs.createNewFile(new Path(bucketPath, file));
    }
    FileStatus[] hoplogs = getBucketHoplogs(getName() + "/0", "");
    assertEquals(hopRefs.size() + files.length, hoplogs.length);

    TimeUnit.MILLISECONDS.sleep(200);
    long target = System.currentTimeMillis();
    List<FileStatus> list = organizer.getOptimizationTargets(target);
    assertEquals(2, list.size());

    for (TrackedReference<Hoplog> ref : hopRefs) {
      ref.increment("test");
    }

    fs.delete(new Path(bucketPath, files[0]), false);

    TimeUnit.MILLISECONDS.sleep(50);
    organizer.markSortedOplogForDeletion(hopRefs, false);

    list = organizer.getOptimizationTargets(target);
    assertEquals(0, list.size());
    organizer.close();
  }

  /**
   * Tests max sequence initialization when file already exists and server starts
   */
  public void testSeqInitialization() throws Exception {
    // create many hoplogs files
    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, 0);
    String[] extensions = { HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION,
        HdfsSortedOplogOrganizer.MINOR_HOPLOG_EXTENSION,
        HdfsSortedOplogOrganizer.MAJOR_HOPLOG_EXTENSION,
        HdfsSortedOplogOrganizer.MAJOR_HOPLOG_EXTENSION};
    for (String string : extensions) {
      Hoplog oplog = organizer.getTmpSortedOplog(null, string);
      createHoplog(1, oplog);
      organizer.makeLegitimate(oplog);
    }

    // a organizer should start creating files starting at 6 as five files already existed
    organizer = new HdfsSortedOplogOrganizer(regionManager, 0);
    Hoplog oplog = organizer.getTmpSortedOplog(null, HdfsSortedOplogOrganizer.MAJOR_HOPLOG_EXTENSION);
    createHoplog(1, oplog);
    organizer.makeLegitimate(oplog);
    assertEquals(6, HdfsSortedOplogOrganizer.getSequenceNumber(oplog));
    organizer.close();
  }

  /**
   * Tests temp file creation and making file legitimate
   */
  public void testMakeLegitimate() throws Exception {
    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, 0);

    // create empty tmp hoplog
    Hoplog oplog = organizer.getTmpSortedOplog(null, HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);
    createHoplog(0, oplog);

    Path hoplogPath = new Path(testDataDir, getName() + "/0/" + oplog.getFileName());
    FileSystem fs = hdfsStore.getFileSystem();
    FileStatus hoplogStatus = fs.getFileStatus(hoplogPath);
    assertNotNull(hoplogStatus);

    organizer.makeLegitimate(oplog);

    try {
      hoplogStatus = fs.getFileStatus(hoplogPath);
      assertNull(hoplogStatus);
    } catch (FileNotFoundException e) {
      // tmp file is renamed hence should not exist, exception expected
    }

    assertTrue(oplog.getFileName().endsWith(HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION));
    hoplogPath = new Path(testDataDir, getName() + "/0/" + oplog.getFileName());
    hoplogStatus = fs.getFileStatus(hoplogPath);
    assertNotNull(hoplogStatus);
  }

  /**
   * Tests hoplog file name comparator
   */
  public void testHoplogFileComparator() throws IOException {
    String name1 = "bucket1-10-3.hop";
    String name2 = "bucket1-1-20.hop";
    String name3 = "bucket1-30-201.hop";
    String name4 = "bucket1-100-201.hop";

    TreeSet<TrackedReference<Hoplog>> list = new TreeSet<TrackedReference<Hoplog>>(new HoplogComparator());
    // insert soplog is the list out of expected order
    hdfsStore.getFileSystem();
    list.add(new TrackedReference<Hoplog>(new HFileSortedOplog(hdfsStore, new Path(testDataDir, name2), blockCache, stats, storeStats)));
    list.add(new TrackedReference<Hoplog>(new HFileSortedOplog(hdfsStore, new Path(testDataDir, name4), blockCache, stats, storeStats)));
    list.add(new TrackedReference<Hoplog>(new HFileSortedOplog(hdfsStore, new Path(testDataDir, name1), blockCache, stats, storeStats)));
    list.add(new TrackedReference<Hoplog>(new HFileSortedOplog(hdfsStore, new Path(testDataDir, name3), blockCache, stats, storeStats)));

    Iterator<TrackedReference<Hoplog>> iter = list.iterator();
    assertEquals(name4, iter.next().get().getFileName());
    assertEquals(name3, iter.next().get().getFileName());
    assertEquals(name2, iter.next().get().getFileName());
    assertEquals(name1, iter.next().get().getFileName());
  }

  /**
   * Tests clear on a set of hoplogs.
   */
  public void testClear() throws Exception {
    int bucketId = (int) System.nanoTime();
    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, bucketId);

    // flush and create hoplog
    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    items.add(new TestEvent(("1"), ("1-1")));
    items.add(new TestEvent(("4"), ("1-4")));
    organizer.flush(items.iterator(), items.size());

    items.clear();
    items.add(new TestEvent(("1"), ("2-1")));
    items.add(new TestEvent(("3"), ("2-3")));
    organizer.flush(items.iterator(), items.size());

    items.clear();
    items.add(new TestEvent(("3"), ("3-3")));
    items.add(new TestEvent(("5"), ("3-5")));
    organizer.flush(items.iterator(), items.size());

    // check file existence in bucket directory
    FileStatus[] hoplogs = getBucketHoplogs(getName() + "/" + bucketId, HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);

    // expect 3 files are 3 flushes
    assertEquals(3, hoplogs.length);

    organizer.clear();

    // check that all files are now expired
    hoplogs = getBucketHoplogs(getName() + "/" + bucketId, HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);
    FileStatus[] exs = getBucketHoplogs(getName() + "/" + bucketId, HdfsSortedOplogOrganizer.EXPIRED_HOPLOG_EXTENSION);
    FileStatus[] valids = HdfsSortedOplogOrganizer.filterValidHoplogs(hoplogs, exs);
    assertEquals(Collections.EMPTY_LIST, Arrays.asList(valids));

    assertEquals(0, stats.getActiveFileCount());
    assertEquals(0, stats.getInactiveFileCount());
  }

  public void testFixedIntervalMajorCompaction() throws Exception {
    final AtomicInteger majorCReqCount = new AtomicInteger(0);

    final Compactor compactor = new AbstractCompactor() {
      @Override
      public boolean compact(boolean isMajor, boolean isForced) throws IOException {
        majorCReqCount.incrementAndGet();
        return true;
      }
    };

    HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, 0) {
      @Override
      public synchronized Compactor getCompactor() {
        return compactor;
      }
    };

    regionManager.addOrganizer(0, organizer);

    System.setProperty(HoplogConfig.JANITOR_INTERVAL_SECS, "1");
    HDFSRegionDirector.resetJanitor();

    alterMajorCompaction(hdfsStore, true);

    // create hoplog in the past, 90 seconds before current time
    organizer.hoplogCreated(getName(), 0, new TestHoplog(hdfsStore, 100, System.currentTimeMillis() - 90000));
    TimeUnit.MILLISECONDS.sleep(50);
    organizer.hoplogCreated(getName(), 0, new TestHoplog(hdfsStore, 100, System.currentTimeMillis() - 90000));

    List<TrackedReference<Hoplog>> hoplogs = organizer.getSortedOplogs();
    assertEquals(2, hoplogs.size());

    for (int i = 0; i < 3; i++) {
      TimeUnit.SECONDS.sleep(1);
      assertEquals(0, majorCReqCount.get());
    }
    HDFSStoreMutator mutator = hdfsStore.createHdfsStoreMutator();
    mutator.getCompactionConfigMutator().setMajorCompactionIntervalMins(1);
    hdfsStore.alter(mutator);
    TimeUnit.SECONDS.sleep(5);
    assertTrue(3 < majorCReqCount.get());
  }

  public void testCorruptHfileBucketFail() throws Exception {
    int port = AvailablePortHelper.getRandomAvailableTCPPort();
    MiniDFSCluster cluster = initMiniCluster(port ,1);

    hsf.setHomeDir("Store-1");
    hsf.setNameNodeURL("hdfs://127.0.0.1:" + port);
    HDFSStoreImpl store1 = (HDFSStoreImpl) hsf.create("Store-1");

    // create a corrupt file
    FileSystem fs = store1.getFileSystem();
    for (int i = 0; i < 113; i++) {
      FSDataOutputStream opStream = fs.create(new Path("Store-1/region-1/" + i + "/1-1-1.hop"));
      opStream.writeBytes("Some random corrupt file");
      opStream.close();
    }

    // create region with store
    regionfactory.setHDFSStoreName(store1.getName());
    Region<Object, Object> region1 = regionfactory.create("region-1");
    ExpectedException ex = TestUtils.addExpectedException("CorruptHFileException");
    try {
      region1.get("key");
      fail("get should have failed with corrupt file error");
    } catch (HDFSIOException e) {
      // expected
    } finally {
      ex.remove();
    }

    region1.destroyRegion();
    store1.destroy();
    cluster.shutdown();
    FileUtils.deleteDirectory(new File("hdfs-test-cluster"));
  }

  public void testMaxOpenReaders() throws Exception {
    System.setProperty("hoplog.bucket.max.open.files", "5");
    HoplogOrganizer<? extends PersistedEventImpl> organizer = new HdfsSortedOplogOrganizer(regionManager, 0);

    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    for (int i = 0; i < 10; i++) {
      items.clear();
      items.add(new TestEvent("" + i, "" + i));
      organizer.flush(items.iterator(), items.size());
    }

    HdfsSortedOplogOrganizer bucket = (HdfsSortedOplogOrganizer) organizer;
    List<TrackedReference<Hoplog>> hoplogs = bucket.getSortedOplogs();
    int closedCount = 0 ;
    for (TrackedReference<Hoplog> hoplog : hoplogs) {
      HFileSortedOplog hfile = (HFileSortedOplog) hoplog.get();
      if (hfile.isClosed()) {
        closedCount++;
      }
    }
    assertEquals(10, closedCount);
    assertEquals(10, stats.getActiveFileCount());
    assertEquals(0, stats.getActiveReaderCount());

    byte[] keyBytes1 = BlobHelper.serializeToBlob("1");
    organizer.read(keyBytes1).getValue();

    closedCount = 0 ;
    for (TrackedReference<Hoplog> hoplog : hoplogs) {
      HFileSortedOplog hfile = (HFileSortedOplog) hoplog.get();
      if (hfile.isClosed()) {
        closedCount++;
      }
    }
    assertEquals(5, closedCount);
    assertEquals(10, stats.getActiveFileCount());
    assertEquals(0, stats.getInactiveFileCount());
    assertEquals(5, stats.getActiveReaderCount());

    organizer.getCompactor().compact(false, false);
    assertEquals(1, stats.getActiveFileCount());
    assertEquals(0, stats.getActiveReaderCount());
    assertEquals(0, stats.getInactiveFileCount());
  }

  public void testConcurrentReadInactiveClose() throws Exception {
    final HoplogOrganizer<? extends PersistedEventImpl> organizer = regionManager.create(0);
    alterMinorCompaction(hdfsStore, true);

    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    for (int i = 0; i < 4; i++) {
      items.clear();
      items.add(new TestEvent("" + i, "" + i));
      organizer.flush(items.iterator(), items.size());
    }

    final byte[] keyBytes1 = BlobHelper.serializeToBlob("1");
    class ReadTask implements Runnable {
      public void run() {
        try {
          organizer.read(keyBytes1);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    ScheduledExecutorService[] readers = new ScheduledExecutorService[10];
    for (int i = 0; i < readers.length; i++) {
      readers[i] = Executors.newSingleThreadScheduledExecutor();
      readers[i].scheduleWithFixedDelay(new ReadTask(), 0, 1, TimeUnit.MILLISECONDS);
    }

    for (int i = 0; i < 100; i++) {
      items.clear();
      items.add(new TestEvent("" + i, "" + i));
      organizer.flush(items.iterator(), items.size());
    }

    for (int i = 0; i < readers.length; i++) {
      readers[i].shutdown();
      readers[i].awaitTermination(1, TimeUnit.SECONDS);
      TimeUnit.MILLISECONDS.sleep(50);
    }

    for (int i = 0; i < 20; i++) {
      if (stats.getActiveFileCount() < 4) {
        break;
      }
      organizer.getCompactor().compact(false, false);
    }

    organizer.performMaintenance();
    TimeUnit.SECONDS.sleep(1);

    assertTrue("" + stats.getActiveFileCount(), stats.getActiveFileCount() <= 4);
    assertEquals(stats.getActiveReaderCount(), stats.getActiveReaderCount());
    assertEquals(0, stats.getInactiveFileCount());
  }

  public void testEmptyBucketCleanup() throws Exception {
    HdfsSortedOplogOrganizer o = new HdfsSortedOplogOrganizer(regionManager, 0);
    long target = System.currentTimeMillis();
    o.getOptimizationTargets(target);
    // making sure empty bucket is not causing IO errors. no assertion needed
    // for this test case.
  }

  public void testExpiredFilterAtStartup() throws Exception {
    HdfsSortedOplogOrganizer bucket = new HdfsSortedOplogOrganizer(regionManager, 0);

    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    items.add(new TestEvent(("1"), ("1-1")));
    items.add(new TestEvent(("4"), ("1-4")));
    bucket.flush(items.iterator(), items.size());

    items.clear();
    items.add(new TestEvent(("1"), ("2-1")));
    items.add(new TestEvent(("3"), ("2-3")));
    bucket.flush(items.iterator(), items.size());

    FileStatus[] files = getBucketHoplogs(getName() + "/" + 0,
        HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);
    assertEquals(2, files.length);

    files = getBucketHoplogs(getName() + "/" + 0,
        HdfsSortedOplogOrganizer.EXPIRED_HOPLOG_EXTENSION);
    assertEquals(0, files.length);

    HdfsSortedOplogOrganizer bucket2 = new HdfsSortedOplogOrganizer(regionManager, 0);
    List<TrackedReference<Hoplog>> hoplogs = bucket2.getSortedOplogs();
    assertEquals(2, hoplogs.size());

    bucket.clear();

    files = getBucketHoplogs(getName() + "/" + 0,
        HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);
    assertEquals(2, files.length);

    files = getBucketHoplogs(getName() + "/" + 0,
        HdfsSortedOplogOrganizer.EXPIRED_HOPLOG_EXTENSION);
    assertEquals(2, files.length);

    bucket2 = new HdfsSortedOplogOrganizer(regionManager, 0);
    hoplogs = bucket2.getSortedOplogs();
    assertEquals(0, hoplogs.size());

    items.clear();
    items.add(new TestEvent(("1"), ("2-1")));
    items.add(new TestEvent(("3"), ("2-3")));
    bucket.flush(items.iterator(), items.size());

    bucket2 = new HdfsSortedOplogOrganizer(regionManager, 0);
    hoplogs = bucket2.getSortedOplogs();
    assertEquals(1, hoplogs.size());
    bucket.close();
    bucket2.close();
  }

  public void testExpireFilterRetartAfterClear() throws Exception {
    HdfsSortedOplogOrganizer bucket = new HdfsSortedOplogOrganizer(regionManager, 0);

    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    items.add(new TestEvent(("1"), ("1-1")));
    items.add(new TestEvent(("4"), ("1-4")));
    bucket.flush(items.iterator(), items.size());

    items.clear();
    items.add(new TestEvent(("1"), ("2-1")));
    items.add(new TestEvent(("3"), ("2-3")));
    bucket.flush(items.iterator(), items.size());

    FileStatus[] files = getBucketHoplogs(getName() + "/" + 0,
        HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);
    assertEquals(2, files.length);

    files = getBucketHoplogs(getName() + "/" + 0,
        HdfsSortedOplogOrganizer.EXPIRED_HOPLOG_EXTENSION);
    assertEquals(0, files.length);

    HdfsSortedOplogOrganizer bucket2 = new HdfsSortedOplogOrganizer(regionManager, 0);
    List<TrackedReference<Hoplog>> hoplogs = bucket2.getSortedOplogs();
    assertEquals(2, hoplogs.size());

    bucket.clear();

    files = getBucketHoplogs(getName() + "/" + 0,
        HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);
    assertEquals(2, files.length);

    files = getBucketHoplogs(getName() + "/" + 0,
        HdfsSortedOplogOrganizer.EXPIRED_HOPLOG_EXTENSION);
    assertEquals(2, files.length);

    bucket2 = new HdfsSortedOplogOrganizer(regionManager, 0);
    hoplogs = bucket2.getSortedOplogs();
    assertEquals(0, hoplogs.size());
    bucket.close();
    bucket2.close();
  }

  /**
   * tests maintenance does not fail even if there are no hoplogs
   */
  public void testNoFileJanitor() throws Exception {
    HoplogOrganizer<? extends PersistedEventImpl> organizer;
    organizer = regionManager.create(0);
    organizer.performMaintenance();
  }

  public void testValidHoplogRegex() {
    String[] valid = {"1-1-1.hop", "1-1-1.ihop", "1-1-1.chop"};
    String[] invalid = {"1-1-1.khop", "1-1-1.hop.tmphop", "1-1-1.hop.ehop", "1-1-.hop", "-1-1.hop"};

    for (String string : valid) {
      Matcher matcher = HdfsSortedOplogOrganizer.SORTED_HOPLOG_PATTERN.matcher(string);
      assertTrue(matcher.matches());
    }

    for (String string : invalid) {
      Matcher matcher = HdfsSortedOplogOrganizer.SORTED_HOPLOG_PATTERN.matcher(string);
      assertFalse(matcher.matches());
    }
  }

  public void testOneHoplogMajorCompaction() throws Exception {
    HoplogOrganizer<? extends PersistedEventImpl> organizer = new HdfsSortedOplogOrganizer(regionManager, 0);
    alterMajorCompaction(hdfsStore, true);

    ArrayList<TestEvent> items = new ArrayList<TestEvent>();
    items.add(new TestEvent(("1"), ("1-1")));
    organizer.flush(items.iterator(),items.size());

    FileStatus[] files = getBucketHoplogs(getName() + "/0", HdfsSortedOplogOrganizer.FLUSH_HOPLOG_EXTENSION);
    assertEquals(1, files.length);

    //Minor compaction will not perform on 1 .hop file
    organizer.getCompactor().compact(false, false);
    files = getBucketHoplogs(getName() + "/0", HdfsSortedOplogOrganizer.MINOR_HOPLOG_EXTENSION);
    assertEquals(0, files.length);

    //Major compaction will perform on 1 .hop file
    organizer.getCompactor().compact(true, false);
    files = getBucketHoplogs(getName() + "/0", HdfsSortedOplogOrganizer.MAJOR_HOPLOG_EXTENSION);
    assertEquals(1, files.length);
    String hoplogName =files[0].getPath().getName();
    files = getBucketHoplogs(getName() + "/0", HdfsSortedOplogOrganizer.MINOR_HOPLOG_EXTENSION);
    assertEquals(0, files.length);

    organizer.getCompactor().compact(true, false);
    files = getBucketHoplogs(getName() + "/0", HdfsSortedOplogOrganizer.MAJOR_HOPLOG_EXTENSION);
    assertEquals(1, files.length);
    assertEquals(hoplogName, files[0].getPath().getName());

    //Minor compaction does not convert major compacted file
    organizer.getCompactor().compact(false, false);
    files = getBucketHoplogs(getName() + "/0", HdfsSortedOplogOrganizer.MINOR_HOPLOG_EXTENSION);
    assertEquals(0, files.length);

    files = getBucketHoplogs(getName() + "/0", HdfsSortedOplogOrganizer.MAJOR_HOPLOG_EXTENSION);
    assertEquals(1, files.length);
    assertEquals(hoplogName, files[0].getPath().getName());

    files = getBucketHoplogs(getName() + "/0", HdfsSortedOplogOrganizer.EXPIRED_HOPLOG_EXTENSION);
    assertEquals(1, files.length);
    assertNotSame(hoplogName + HdfsSortedOplogOrganizer.EXPIRED_HOPLOG_EXTENSION, files[0].getPath().getName() );
  }

  public void testExposeCleanupInterval() throws Exception {
    FileSystem fs = hdfsStore.getFileSystem();
    Path cleanUpIntervalPath = new Path(hdfsStore.getHomeDir(), HoplogConfig.CLEAN_UP_INTERVAL_FILE_NAME);
    assertTrue(fs.exists(cleanUpIntervalPath));
    long interval = HDFSCompactionConfig.DEFAULT_OLD_FILE_CLEANUP_INTERVAL_MINS
        *60 * 1000;
    assertEquals(interval, HoplogUtil.readCleanUpIntervalMillis(fs,cleanUpIntervalPath));
  }

  @Override
  protected void setUp() throws Exception {
    System.setProperty(HoplogConfig.JANITOR_INTERVAL_SECS, "" + HoplogConfig.JANITOR_INTERVAL_SECS_DEFAULT);
    super.setUp();
  }
}

redpajama_set_name: RedPajamaGithub


text:
<?php
defined('ABSPATH') or die();

/* Posts/Pages Shortcode */

add_shortcode( 'spingo_calendar', 'calendar_shortcode' );

function addAttributes($attrs, $map) {
	$params = array();
	foreach($map as $shortcodeParam => $embedParam) {
		if (array_key_exists($shortcodeParam, $attrs)) {
			$params[$embedParam] = $attrs[$shortcodeParam];
			if ($params[$embedParam] === "true") {
				$params[$embedParam] = true;
			} else if ($params[$embedParam] === "false") {
				$params[$embedParam] = false;
			} else if (is_numeric($params[$embedParam])) {
				$params[$embedParam] = intval($params[$embedParam]);
			}
		}
	}
	return $params;
}

function calendar_shortcode($attrs) {
	$options = get_option('spingo__settings');

	$calendarParams = array_merge(
		array(
			'subdomain' => $options['spingo__subdomain']
		),
		addAttributes($attrs, array(
			'calendar_id' => 'id',
			'calendar_parent_url' => 'parentUrl',
			'calendar_twitter_handle' => 'twitterHandle',
			'calendar_user_location' => 'userLocation',
			'calendar_postal_code' => 'postalCode',
			'calendar_radius_miles' => 'radiusMiles'
		))
	);

	$modeParams = addAttributes($attrs, array(
		'calendar_mode_type' => 'type',
		'calendar_mode_id' => 'id'
	));
	if (count($modeParams) > 0) {
		$calendarParams['mode'] = $modeParams;
	}

	$params = array_merge(
		array(
			'authToken' => $options['spingo__authToken'],
			'calendar' => $calendarParams
		),
		addAttributes($attrs, array(
			'pushstate' => 'pushState',
			'default_view' => 'defaultView',
			'section_ids' => 'sectionIDs',
			'default_color' => 'defaultColor',
			'accent_color' => 'accentColor',
			'fixed_top_offset' => 'fixedTopOffset',
			'dark_background' => 'darkBackground'
		))
	);
	if (array_key_exists('section_ids', $attrs)) {
		$ids = explode(',', $attrs['section_ids']);
		$paramIds = array();
		foreach($ids as $id) {
			$id = intval($id);
			if (!empty($id)) {
				$paramIds[] = $id;
			}
		}
		if (count($ids) > 0) {
			$params['sectionIDs'] = $paramIds;
		}
	}

	echo '

';
	echo "";
	echo '';
}


text:
package org.apache.log4j.defaultInit;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.log4j.*;

import java.util.Enumeration;

public class TestCase2 extends TestCase {
  public TestCase2(String name) {
    super(name);
  }

  public void setUp() {
  }

  public void tearDown() {
    LogManager.shutdown();
  }

  public void xmlTest() {
    Logger root = Logger.getRootLogger();
    boolean rootIsConfigured = root.getAllAppenders().hasMoreElements();
    assertTrue(rootIsConfigured);

    Enumeration e = root.getAllAppenders();
    Appender appender = (Appender) e.nextElement();
    assertEquals(appender.getName(), "D1");
  }

  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(new TestCase2("xmlTest"));

    return suite;
  }
}


text:
module TimeSeriesMath
  VERSION = "0.1.1"
end


text:
/*
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
/*
 * This code was generated by https://github.com/googleapis/google-api-java-client-services/
 * Modify at your own risk.
 */

package com.google.api.services.mybusinessbusinessinformation.v1.model;

/**
 * Represents a Location that is present on Google. This can be a location that has been claimed by
 * the user, someone else, or could be unclaimed.
 *
 *
 This is the Java data model class that specifies how to parse/serialize into the JSON that is
 * transmitted over HTTP when working with the My Business Business Information API. For a detailed
 * explanation see:
 * https://developers.google.com/api-client-library/java/google-http-java-client/json
 *

 *
 * @author Google, Inc.
 */
@SuppressWarnings("javadoc")
public final class GoogleLocation extends com.google.api.client.json.GenericJson {

  /**
   * The sparsely populated Location information. This field can be re-used in CreateLocation if it
   * is not currently claimed by a user.
   * The value may be {@code null}.
   */
  @com.google.api.client.util.Key
  private Location location;

  /**
   * Resource name of this GoogleLocation, in the format `googleLocations/{googleLocationId}`.
   * The value may be {@code null}.
   */
  @com.google.api.client.util.Key
  private java.lang.String name;

  /**
   * A URL that will redirect the user to the request admin rights UI. This field is only present if
   * the location has already been claimed by any user, including the current user.
   * The value may be {@code null}.
   */
  @com.google.api.client.util.Key
  private java.lang.String requestAdminRightsUri;

  /**
   * The sparsely populated Location information. This field can be re-used in CreateLocation if it
   * is not currently claimed by a user.
   * @return value or {@code null} for none
   */
  public Location getLocation() {
    return location;
  }

  /**
   * The sparsely populated Location information. This field can be re-used in CreateLocation if it
   * is not currently claimed by a user.
   * @param location location or {@code null} for none
   */
  public GoogleLocation setLocation(Location location) {
    this.location = location;
    return this;
  }

  /**
   * Resource name of this GoogleLocation, in the format `googleLocations/{googleLocationId}`.
   * @return value or {@code null} for none
   */
  public java.lang.String getName() {
    return name;
  }

  /**
   * Resource name of this GoogleLocation, in the format `googleLocations/{googleLocationId}`.
   * @param name name or {@code null} for none
   */
  public GoogleLocation setName(java.lang.String name) {
    this.name = name;
    return this;
  }

  /**
   * A URL that will redirect the user to the request admin rights UI. This field is only present if
   * the location has already been claimed by any user, including the current user.
   * @return value or {@code null} for none
   */
  public java.lang.String getRequestAdminRightsUri() {
    return requestAdminRightsUri;
  }

  /**
   * A URL that will redirect the user to the request admin rights UI. This field is only present if
   * the location has already been claimed by any user, including the current user.
   * @param requestAdminRightsUri requestAdminRightsUri or {@code null} for none
   */
  public GoogleLocation setRequestAdminRightsUri(java.lang.String requestAdminRightsUri) {
    this.requestAdminRightsUri = requestAdminRightsUri;
    return this;
  }

  @Override
  public GoogleLocation set(String fieldName, Object value) {
    return (GoogleLocation) super.set(fieldName, value);
  }

  @Override
  public GoogleLocation clone() {
    return (GoogleLocation) super.clone();
  }

}


text:
using Core;
using Core.DataAccess;
using Gama.Common;
using Gama.Socios.DataAccess;
using Gama.Socios.Wpf.FakeServices;
using Gama.Socios.Wpf.Services;
using Gama.Socios.Wpf.ViewModels;
using Gama.Socios.Wpf.Views;
using Microsoft.Practices.Unity;
using NHibernate;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Gama.Socios.Wpf
{
    public class SociosModule : ModuleBase
    {
        public SociosModule(IUnityContainer container, IRegionManager regionManager)
           : base(container, regionManager)
        {

        }

        public override void Initialize()
        {
            RegisterViews();
            RegisterViewModels();
            InitializeNavigation();
        }

        private void RegisterViews()
        {
            Container.RegisterType<object, DashboardView>("DashboardView");
            Container.RegisterType<object, EditarCuotasView>("EditarCuotasView");
            Container.RegisterType<object, EditarPeriodosDeAltaView>("EditarPeriodosDeAltaView");
            Container.RegisterType<object, EditarSocioView>("EditarSocioView");
            Container.RegisterType<object, ListadoDeSociosView>("ListadoDeSociosView");
            Container.RegisterType<object, PanelSwitcherView>("PanelSwitcherView");
            Container.RegisterType<object, SociosContentView>("SociosContentView");
            Container.RegisterType<object, SocioView>("SocioView");
            Container.RegisterType<object, ToolbarView>("ToolbarView");
            Container.RegisterType<object, RightCommandsView>("RightCommandsView");
            Container.RegisterType<object, PreferenciasView>("PreferenciasView");
            Container.RegisterType<object, StatusBarView>("StatusBarView");
        }

        private void RegisterViewModels()
        {
            Container.RegisterType<DashboardViewModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<EditarCuotasViewModel>();
            Container.RegisterType<StatusBarViewModel>();
            Container.RegisterType<EditarPeriodosDeAltaViewModel>();
            Container.RegisterType<EditarSocioViewModel>();
            Container.RegisterType<ListadoDeSociosViewModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<NuevoSocioViewModel>();
            Container.RegisterType<PanelSwitcherViewModel>();
            Container.RegisterType<SociosContentViewModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<SocioViewModel>();
            Container.RegisterType<ToolbarViewModel>();
            Container.RegisterType<PreferenciasViewModel>();
            Container.RegisterType<RightCommandsViewModel>();
            Container.RegisterType<GraficasContentViewModel>(new ContainerControlledLifetimeManager());
        }

        private void InitializeNavigation()
        {
            //RegionManager.RegisterViewWithRegion(RegionNames.PanelSwitcherRegion, typeof(PanelSwitcherView));
            //RegionManager.RegisterViewWithRegion(RegionNames.ToolbarRegion, typeof(ToolbarView));
            //RegionManager.RegisterViewWithRegion(RegionNames.SearchBoxRegion, typeof(SearchBoxView));
            //RegionManager.RegisterViewWithRegion(RegionNames.StatusBarRegion, typeof(StatusBarView));
            //RegionManager.RegisterViewWithRegion(RegionNames.RightCommandsRegion, typeof(RightCommandsView));
            //RegionManager.RegisterViewWithRegion(RegionNames.PreferenciasRegion, typeof(PreferenciasView));
            //RegionManager.RequestNavigate(RegionNames.ContentRegion, "DashboardView");

            //RegionManager.AddToRegion(RegionNames.ContentRegion, Container.Resolve<SociosContentView>());
            //RegionManager.AddToRegion(RegionNames.ContentRegion, Container.Resolve<ContabilidadView>());
            //RegionManager.AddToRegion(RegionNames.SociosTabContentRegion, Container.Resolve<ListadoDeSociosView>());
        }
    }
}


text:
\section{\module{rexec} ---
         Restricted execution framework}

\declaremodule{standard}{rexec}
\modulesynopsis{Basic restricted execution framework.}
\versionchanged[Disabled module]{2.3}

\begin{notice}[warning]
  The documentation has been left in place to help in reading old code
  that uses the module.
\end{notice}

This module contains the \class{RExec} class, which supports
\method{r_eval()}, \method{r_execfile()}, \method{r_exec()}, and
\method{r_import()} methods, which are restricted versions of the standard
Python functions \method{eval()}, \method{execfile()} and
the \keyword{exec} and \keyword{import} statements.
Code executed in this restricted environment will
only have access to modules and functions that are deemed safe; you
can subclass \class{RExec} to add or remove capabilities as desired.

\begin{notice}[warning]
  While the \module{rexec} module is designed to perform as described
  below, it does have a few known vulnerabilities which could be
  exploited by carefully written code.  Thus it should not be relied
  upon in situations requiring ``production ready'' security.  In such
  situations, execution via sub-processes or very careful
  ``cleansing'' of both code and data to be processed may be
  necessary.  Alternatively, help in patching known \module{rexec}
  vulnerabilities would be welcomed.
\end{notice}

\begin{notice}
  The \class{RExec} class can prevent code from performing unsafe
  operations like reading or writing disk files, or using TCP/IP
  sockets.  However, it does not protect against code using extremely
  large amounts of memory or processor time.
\end{notice}

\begin{classdesc}{RExec}{\optional{hooks\optional{, verbose}}}
Returns an instance of the \class{RExec} class.

\var{hooks} is an instance of the \class{RHooks} class or a subclass of it.
If it is omitted or \code{None}, the default \class{RHooks} class is
instantiated.
Whenever the \module{rexec} module searches for a module (even a
built-in one) or reads a module's code, it doesn't actually go out to
the file system itself.  Rather, it calls methods of an \class{RHooks}
instance that was passed to or created by its constructor.  (Actually,
the \class{RExec} object doesn't make these calls --- they are made by
a module loader object that's part of the \class{RExec} object.  This
allows another level of flexibility, which can be useful when changing
the mechanics of \keyword{import} within the restricted environment.)

By providing an alternate \class{RHooks} object, we can control the
file system accesses made to import a module, without changing the
actual algorithm that controls the order in which those accesses are
made.  For instance, we could substitute an \class{RHooks} object that
passes all filesystem requests to a file server elsewhere, via some
RPC mechanism such as ILU.  Grail's applet loader uses this to support
importing applets from a URL for a directory.

If \var{verbose} is true, additional debugging output may be sent to
standard output.
\end{classdesc}

It is important to be aware that code running in a restricted
environment can still call the \function{sys.exit()} function.  To
disallow restricted code from exiting the interpreter, always protect
calls that cause restricted code to run with a
\keyword{try}/\keyword{except} statement that catches the
\exception{SystemExit} exception.  Removing the \function{sys.exit()}
function from the restricted environment is not sufficient --- the
restricted code could still use \code{raise SystemExit}.  Removing
\exception{SystemExit} is not a reasonable option; some library code
makes use of this and would break were it not available.

\begin{seealso}
  \seetitle[http://grail.sourceforge.net/]{Grail Home Page}{Grail is a
            Web browser written entirely in Python.  It uses the
            \module{rexec} module as a foundation for supporting
            Python applets, and can be used as an example usage of
            this module.}
\end{seealso}

\subsection{RExec Objects \label{rexec-objects}}

\class{RExec} instances support the following methods:

\begin{methoddesc}{r_eval}{code}
\var{code} must either be a string containing a Python expression, or
a compiled code object, which will be evaluated in the restricted
environment's \module{__main__} module.  The value of the expression or
code object will be returned.
\end{methoddesc}

\begin{methoddesc}{r_exec}{code}
\var{code} must either be a string containing one or more lines of
Python code, or a compiled code object, which will be executed in the
restricted environment's \module{__main__} module.
\end{methoddesc}

\begin{methoddesc}{r_execfile}{filename}
Execute the Python code contained in the file \var{filename} in the
restricted environment's \module{__main__} module.
\end{methoddesc}

Methods whose names begin with \samp{s_} are similar to the functions
beginning with \samp{r_}, but the code will be granted access to
restricted versions of the standard I/O streams \code{sys.stdin},
\code{sys.stderr}, and \code{sys.stdout}.

\begin{methoddesc}{s_eval}{code}
\var{code} must be a string containing a Python expression, which will
be evaluated in the restricted environment.
\end{methoddesc}

\begin{methoddesc}{s_exec}{code}
\var{code} must be a string containing one or more lines of Python code,
which will be executed in the restricted environment.
\end{methoddesc}

\begin{methoddesc}{s_execfile}{code}
Execute the Python code contained in the file \var{filename} in the
restricted environment.
\end{methoddesc}

\class{RExec} objects must also support various methods which will be
implicitly called by code executing in the restricted environment.
Overriding these methods in a subclass is used to change the policies
enforced by a restricted environment.

\begin{methoddesc}{r_import}{modulename\optional{, globals\optional{,
                             locals\optional{, fromlist}}}}
Import the module \var{modulename}, raising an \exception{ImportError}
exception if the module is considered unsafe.
\end{methoddesc}

\begin{methoddesc}{r_open}{filename\optional{, mode\optional{, bufsize}}}
Method called when \function{open()} is called in the restricted
environment.  The arguments are identical to those of \function{open()},
and a file object (or a class instance compatible with file objects)
should be returned.  \class{RExec}'s default behaviour is allow opening
any file for reading, but forbidding any attempt to write a file.  See
the example below for an implementation of a less restrictive
\method{r_open()}.
\end{methoddesc}

\begin{methoddesc}{r_reload}{module}
Reload the module object \var{module}, re-parsing and re-initializing it.
\end{methoddesc}

\begin{methoddesc}{r_unload}{module}
Unload the module object \var{module} (remove it from the
restricted environment's \code{sys.modules} dictionary).
\end{methoddesc}

And their equivalents with access to restricted standard I/O streams:

\begin{methoddesc}{s_import}{modulename\optional{, globals\optional{,
                             locals\optional{, fromlist}}}}
Import the module \var{modulename}, raising an \exception{ImportError}
exception if the module is considered unsafe.
\end{methoddesc}

\begin{methoddesc}{s_reload}{module}
Reload the module object \var{module}, re-parsing and re-initializing it.
\end{methoddesc}

\begin{methoddesc}{s_unload}{module}
Unload the module object \var{module}.
% XXX what are the semantics of this?
\end{methoddesc}

\subsection{Defining restricted environments \label{rexec-extension}}

The \class{RExec} class has the following class attributes, which are
used by the \method{__init__()} method.  Changing them on an existing
instance won't have any effect; instead, create a subclass of
\class{RExec} and assign them new values in the class definition.
Instances of the new class will then use those new values.  All these
attributes are tuples of strings.

\begin{memberdesc}{nok_builtin_names}
Contains the names of built-in functions which will \emph{not} be
available to programs running in the restricted environment.  The
value for \class{RExec} is \code{('open', 'reload', '__import__')}.
(This gives the exceptions, because by far the majority of built-in
functions are harmless.  A subclass that wants to override this
variable should probably start with the value from the base class and
concatenate additional forbidden functions --- when new dangerous
built-in functions are added to Python, they will also be added to
this module.)
\end{memberdesc}

\begin{memberdesc}{ok_builtin_modules}
Contains the names of built-in modules which can be safely imported.
The value for \class{RExec} is \code{('audioop', 'array', 'binascii',
'cmath', 'errno', 'imageop', 'marshal', 'math', 'md5', 'operator',
'parser', 'regex', 'select', 'sha', '_sre', 'strop',
'struct', 'time')}.  A similar remark about overriding this variable
applies --- use the value from the base class as a starting point.
\end{memberdesc}

\begin{memberdesc}{ok_path}
Contains the directories which will be searched when an \keyword{import}
is performed in the restricted environment.
The value for \class{RExec} is the same as \code{sys.path} (at the time
the module is loaded) for unrestricted code.
\end{memberdesc}

\begin{memberdesc}{ok_posix_names}
% Should this be called ok_os_names?
Contains the names of the functions in the \refmodule{os} module which will be
available to programs running in the restricted environment.  The
value for \class{RExec} is \code{('error', 'fstat', 'listdir',
'lstat', 'readlink', 'stat', 'times', 'uname', 'getpid', 'getppid',
'getcwd', 'getuid', 'getgid', 'geteuid', 'getegid')}.
\end{memberdesc}

\begin{memberdesc}{ok_sys_names}
Contains the names of the functions and variables in the \refmodule{sys}
module which will be available to programs running in the restricted
environment.  The value for \class{RExec} is \code{('ps1', 'ps2',
'copyright', 'version', 'platform', 'exit', 'maxint')}.
\end{memberdesc}

\begin{memberdesc}{ok_file_types}
Contains the file types from which modules are allowed to be loaded.
Each file type is an integer constant defined in the \refmodule{imp} module.
The meaningful values are \constant{PY_SOURCE}, \constant{PY_COMPILED}, and
\constant{C_EXTENSION}.  The value for \class{RExec} is \code{(C_EXTENSION,
PY_SOURCE)}.  Adding \constant{PY_COMPILED} in subclasses is not recommended;
an attacker could exit the restricted execution mode by putting a forged
byte-compiled file (\file{.pyc}) anywhere in your file system, for example
by writing it to \file{/tmp} or uploading it to the \file{/incoming}
directory of your public FTP server.
\end{memberdesc}

\subsection{An example}

Let us say that we want a slightly more relaxed policy than the
standard \class{RExec} class.  For example, if we're willing to allow
files in \file{/tmp} to be written, we can subclass the \class{RExec}
class:

\begin{verbatim}
class TmpWriterRExec(rexec.RExec):
    def r_open(self, file, mode='r', buf=-1):
        if mode in ('r', 'rb'):
            pass
        elif mode in ('w', 'wb', 'a', 'ab'):
            # check filename : must begin with /tmp/
            if file[:5]!='/tmp/':
                raise IOError, "can't write outside /tmp"
            elif (string.find(file, '/../') >= 0 or
                 file[:3] == '../' or file[-3:] == '/..'):
                raise IOError, "'..' in filename forbidden"
        else: raise IOError, "Illegal open() mode"
        return open(file, mode, buf)
\end{verbatim}
%
Notice that the above code will occasionally forbid a perfectly valid
filename; for example, code in the restricted environment won't be
able to open a file called \file{/tmp/foo/../bar}.  To fix this, the
\method{r_open()} method would have to simplify the filename to
\file{/tmp/bar}, which would require splitting apart the filename and
performing various operations on it.  In cases where security is at
stake, it may be preferable to write simple code which is sometimes
overly restrictive, instead of more general code that is also more
complex and may harbor a subtle security hole.


text:
//
//  Player.h
//  MemoryAimbot
//
//  Created by Rahim Mitha on 2014-04-29.
//  Copyright (c) 2014 Rahim Mitha. All rights reserved.
//

#ifndef __MemoryAimbot__Player__
#define __MemoryAimbot__Player__

#include <iostream>
#include <vector>
#include <Windows.h>

//Valid as of Apr 29 2014
//Offsets
const DWORD dwPlayerBase = 0x102AC9C;
const DWORD dwEntityBase = 0x1038314;
const DWORD dwEntitySize = 0x10;

//Entity
const DWORD dwHealth = 0xA4;
const DWORD dwCharacterClass = 0x1524;
const DWORD dwTeam = 0xAC;
const DWORD dwPose;
const DWORD dwMaxHealth = 0x1778;
const DWORD dwCrosshairEntityID;
const DWORD dwCloaked = 0x1C0C
const DWORD dwIsVisible;
const DWORD dwBoneMatrix = 0x5A8;
const DWORD dwAngle = 0x1FC0;
const DWORD dwOrigin = 0x360;

class Player {
public:
	int team;
	int health;
	int maxHealth;
	int pose; //eg. Crouching, standing, scoped
	int isCloaked;
	int crosshairEntityID;
	int characterClass;
	float angle;
	void* boneMatrix;
	float[3] origin;

	bool isAlive;
	bool isVisible;

	std::vector<float> position;
	std::vector<float> velocity;
	std::vector<float> accellaration;

	void ReadInformation(int Player);
};

#endif /* defined(__MemoryAimbot__Player__) */


text:
const m_util = require('common/util/index');
const m_search = require('helper/search');
const swPostMessage = require('helper/sw_post_message.js');
let catalogList = []; //目录列表
let catalogDict = {};
let articleList = []; //文件列表
let articleDict = {};
let sidebarList = []; //sidebar文件列表(sidebar文件也可以在articleDict中索引到)
let bookList = []; //书籍列表
let bookDict = {};
let tagList = [];
let startTime = Date.now();
let isPreload = false;
const sidebarName = '$sidebar$';
const getSidebarPath = (path) => path + '/' + sidebarName + '.md';

BCD.addEvent('mkview', function (ele, option, data) {
  let name = m_util.getRandomName();
  let result;
  if ('idx' in option) {
    let item = data.list[option.idx];
    result = item.summary;
    if (result.length < item.content.length) {
      result += '...';
    }
  } else {
    result = data.content;
  }

  ele.attr('id', name);
  setTimeout(function () { //dom元素展示出来之后再绑定,不然流程图等会有样式问题
    editormd.markdownToHTML(name, {
      markdown: result, //+ "\r\n" + $("#append-test").text(),
      // htmlDecode: true, // 开启 HTML 标签解析,为了安全性,默认不开启
      htmlDecode: "style,script,iframe", // you can filter tags decode
      //toc             : false,
      tocm: true, // Using [TOCM]
      //tocContainer    : "#custom-toc-container", // 自定义 ToC 容器层
      //gfm             : false,
      //tocDropdown     : true,
      // markdownSourceCode : true, // 是否保留 Markdown 源码,即是否删除保存源码的 Textarea 标签
      emoji: true,
      taskList: true,
      tex: true, // 默认不解析
      flowChart: true, // 默认不解析
      sequenceDiagram: true // 默认不解析
    });
    if (result.indexOf('[TOC]') > -1 && location.hash.indexOf('.md') > 0) { //兼容TOC目录
      let baseHash = location.hash.replace(/\.md\/.*/, '.md');
      $('#' + name).html($('#' + name).html()
        .replace(/href="#([^"]*)/g, function ($0, $1) {
          if ($1) {
            return 'href="' + baseHash + '/' + $1;
          }
          return $0
        }).replace(/name="([^"]*)/g, function ($0, $1) {
          if ($1) {
            return 'name="' + baseHash.substr(1) + '/' + $1;
          }
          return $0
        }));
    }
    $('a[href^="http"]').attr('target', '_blank');
  }, 0);
});

const getName = (path) => {
  let arr = path.match(/\/([^/.]+)[.\w-_]+$/);
  return arr ? arr[1] : '';
}

const getURL = (o) => o.path + '?mtime=' + o.mtime;

const getPath = (pathWithSearch) => decodeURIComponent(pathWithSearch.replace(location.origin + '/', '').replace(/\?[^?]+/, ''));

const getSortContent = (content, paragraph = 10) => {
  let len = 500;
  let minLen = len / 2;
  let ret = content.substring(0, len);
  let partCount = 0;
  let partIndex = 0;
  ret.replace(/([^\n]*)(\n|
|<\/p>)/g, function ($0, $1, $2, idx) {
    partCount++;
    if (partCount > paragraph && $1.length > 10 && partIndex === 0) {
      partIndex = idx;
    }
    if (partCount == 15 && partIndex === 0) {
      partIndex = idx;
    }
  });
  if (partIndex > 0) {
    ret = ret.substring(0, partIndex);
    if (ret.length < len * 0.7) {
      return ret;
    }
  }
  let getContent = (str, reg) => {
    let arr = str.split(reg).filter(o => !!o);
    let count = 0;
    if (arr && arr.length > 2) {
      let idx = arr.length - 1;
      if (arr.some((o, i) => {
          count += o.length;
          if (count > minLen && i > 1) {
            idx = i;
            return true;
          }
        })) {
        return str.substr(0, str.lastIndexOf(arr[idx])).replace(/[#\s]+$/, '');
      }
      return str;
    }
  }
  let con = getContent(ret, /\s*#+\s*/);
  if (con) {
    return con;
  }
  con = getContent(ret, /\s+/);
  if (con) {
    return con;
  }
  return ret;
}

const processItem = (item, content)=>{
  if(item.title==sidebarName){
    item.content = content;
    return item;
  }
  let isRaw = true;
  // let start = content.indexOf('---');
  // if(start>-1){
  //   let end;
  //   if(start===0){
  //     start = start+3;
  //     end = content.substring(start).indexOf('---') + start;
  //   }else{
  //     end = start;
  //     start = 0;
  //   }
  //   let arr = content.substring(start, end).match(/([^:\n]+:[^\n]+)/g);
  //   if(arr){
  //     let attrDict = {};
  //     arr.forEach(function(o){
  //       let point = o.indexOf(':');
  //       attrDict[o.substring(0, point)] = o.substring(point+1);
  //     });
  //     item.title = attrDict.title || item.title;
  //     isRaw = false;
  //     content = content.substring(end+3).trim();
  //     if(attrDict.dest_url){
  //       content = '链接:['+attrDict.dest_url+']('+attrDict.dest_url+')'
  //     }
  //   }
  // }
  if(isRaw){
    let arr = content.match(/^[\s]*#[^\n]+[\s]*/);
    if(arr){
     let title = arr[0];
     item.title = title.replace(/[#\s]+/, '').trim();
     content = content.replace(title, '');
     isRaw = false;
    }
  }

  item.content = content = (content || '').replace(/^[\s]*---[-]*/, '');
  item.tfList = m_search.getTFs(content);
  item.summary = getSortContent(content);
  return item;
};

const preload = (obj) => {
  let count = 0;
  for (var pathWithSearch in obj) {
    let path = getPath(pathWithSearch);
    let item;
    if (item = articleDict[path]) {
      count++;
      processItem(item, obj[pathWithSearch]);
    }
  }
  let totalList = sidebarList.concat(articleList);
  let existDict = {};
  totalList.forEach(o => {
    existDict[location.origin + '/' + o.path] = 1;
  });

  swPostMessage({
    m: 'delete_not_exist_article',
    dict: existDict
  });

  if (isPreload) {
    if (count) {
      console.log('文章同步成功(' + count + '篇)!可以离线使用');
    } else {
      console.log('文章同步成功!(无更新内容)');
    }
    return false;
  } else {
    isPreload = true;
    console.log('本地文章加载成功(' + count + '/' + (articleList.length + sidebarList.length) + '个文件)');
  }
  return true;
};

const init = (list) => {
  catalogList = []; //目录列表
  articleList = []; //文件列表
  sidebarList = [];
  bookList = [];
  let tagSet = new Set();
  let processArticle = (o) => {
    let {
      path = '', mtime
    } = o;
    if (o.isDirectory) {
      let tags = path.split('/').slice(1);
      tags.forEach(o => tagSet.add(o));
      let item = {
        path,
        time: m_util.getTime(mtime),
        href: '#!/' + encodeURIComponent(o.path),
        title: path.slice(path.lastIndexOf('/') + 1),
        tagList: tags
      };
      catalogList.push(item);
    } else {
      let tags = path.split('/').slice(1, -1);
      tags.forEach(o => tagSet.add(o));
      let item = {
        path,
        mtime,
        href: '#!/' + encodeURIComponent(o.path),
        title: getName(path),
        time: m_util.getTime(mtime),
        tagList: tags
      };
      if (articleDict[path]) {
        item = $.extend(articleDict[path], item);
      } else {
        articleDict[path] = item;
      }
      articleList.push(item);
    }
  };
  list.forEach(processArticle);
  articleList = articleList.filter(o => {
    if (o.title == sidebarName) {
      sidebarList.push(o);
      return false;
    }
    return true;
  });
  catalogList = catalogList.filter(o => {
    if (articleDict[getSidebarPath(o.path)]) {
      bookDict[o.path] = o;
      bookList.push(o);
      return false;
    }
    catalogDict[o.path] = o;
    return true;
  });
  articleList = articleList.sort((a, b) => {
    return b.mtime - a.mtime;
  });
  tagList = [...tagSet];
};

let processCount = 0;
//先用缓存,请求回来再更新
const initArticle = new Promise((resolve) => {
  BCD.ajaxCache('./json/article.json', (data) => {
    init(data);
    processCount++;
    if (processCount === 2) { //如果网络请求失败,这里不会被执行
      let totalList = sidebarList.concat(articleList);
      swPostMessage({
        m: 'preloadAtricle',
        list: totalList.map(getURL)
      }, preload);
    }
    resolve();
    return 1; //缓存数据到localStorage
  }, 0, 1E3, true);
});

//获取包含相关tag文章列表
const getTagArticles = (tag) => {
  if (tag) {
    return articleList.filter(o => o.tagList &&
      o.tagList.indexOf(tag) > -1);
  }
  return articleList;
};

const fetchContent = (list) => {
  let ajaxList = list.filter(o => articleDict[o.path] && !articleDict[o.path].content).map(o => $.ajax({
    url: getURL(o),
    success(str) {
      articleDict[o.path] = processItem(o, str);
    }
  }));
  return new Promise(function (resolve) {
    $.when.apply(this, ajaxList).then(resolve, resolve);
  });
};

const getList = (method) => (tag, page = 0, count = 10) => {
  page = parseInt(page || 0);
  let start = page * count;
  let totalList = method(tag);
  let list = totalList.slice(start, start + count);
  return fetchContent(list).then(() => {
    return {
      tag,
      page,
      count,
      num: totalList.length,
      list: list.map(o => articleDict[o.path]).filter(o => !!(o && o.content))
    };
  });
};

const getChildCatalog = (path) => {
  let catalog = catalogDict[path];
  if (catalog) {
    let tagList = catalog.tagList;
    let tagLength = tagList.length + 1;
    return bookList.concat(catalogList).filter(o => o.tagList.length &&
      tagList.every((tag, i) => o.tagList.length == tagLength && tag == o.tagList[i]));
  }
  return [];
};

const getCatalogArticles = (path) => {
  let catalog = catalogDict[path];
  if (catalog) {
    let tagList = catalog.tagList;
    return articleList.filter(o => o.tagList.length &&
      tagList.every((tag, i) => tag == o.tagList[i])).sort((a, b) => a.tagList.length - b.tagList.length);
  }
  return [];
};

const testItem = (reg, item) => {
  let testType = 0;
  let obj = {};
  let searchWeight = 0;
  let titleMatchDict = {};
  let contentMatchDict = {};
  if (reg.test(item.title)) {
    obj.title = item.title.replace(reg, function ($0) {
      if (titleMatchDict[$0]) {
        titleMatchDict[$0] ++;
      }else{
        titleMatchDict[$0] = 1;
      }
      return '' + $0 + '';
    });
    testType += 1;
    let titleMathLength = 0;
    for (var key in titleMatchDict) {
      titleMathLength += /\w/.test(key) ? titleMatchDict[key] : Math.pow(1.6, key.length-1) * titleMatchDict[key];
    }
    searchWeight += titleMathLength / item.title.length;
  }
  if (item.content && reg.test(item.content)) {
    let pointList = [];
    obj.content = item.content.replace(reg, function ($0, point) {
      if (contentMatchDict[$0]) {
        contentMatchDict[$0]++;
      } else{
        contentMatchDict[$0] = 1;
      }
      let weight = /\w/.test($0) ? 2 : $0.length;
      pointList.push({
        point,
        weight
      });
      return '' + $0 + '';
    });
    pointList = pointList.sort((a, b) => b.weight - a.weight);
    let startPoint = pointList[0].point;
    let start = startPoint - 30;
    let summary = item.content.substr(start < 0 ? 0 : start);
    start = summary.search(/[。\n\r]/);
    if (start < startPoint) {
      summary = getSortContent(summary.substr(start).replace(/^[。\s]*/, ''), 5);
    } else {
      summary = getSortContent(summary.replace(/^[。\s]*/, ''), 5);
    }
    obj.summary = summary.replace(reg, function ($0) {
      return '' + $0 + '';
    });
    testType += 2;
    let contentMathLength = 0;

    for (var key in contentMatchDict) {
      contentMathLength += /\w/.test(key) ? contentMatchDict[key] : Math.pow(1.6, key.length-1) * contentMatchDict[key];
    }
    searchWeight += contentMathLength / Math.pow(item.content.length, 0.6);
  }
  obj.testType = testType;
/*******calculate search weight**********/

  obj.searchWeight = searchWeight;
  return Object.assign({}, item, obj);
};

const searchList = (word, callback, isCommend = false) => {
  let reg = m_search.getGlobalRegex(word);
  let fitList = [];
  let remainList = [];
  let ajaxList = [];
  let totalList = articleList.filter(o => o);

  const searchCallback = (list) => {
    let resultList = list.filter(o => o.testType > 0).sort((a, b) => {
      let ret = b.searchWeight - a.searchWeight;
      if(ret===0){
        return b.content.length - a.content.length + (b.mtime - a.mtime) / 1E5;
      }
      return ret;
    });
    if (resultList.length || list.length >= totalList.length) {
      console.table(resultList.map(o => {
        return {
          path: o.path,
          searchWeight: o.searchWeight
        };
      }));
    }
    callback({
      totalNum: totalList.length,
      checkNum: list.length,
      searchWord: word,
      list: resultList
    });
  };
  const batchProcess = (list, next) => {
    let subList = list.splice(0, 10);
    fetchContent(subList).then(() => {
      searchCallback(subList.map(o => testItem(reg, articleDict[o.path])));
      if (list.length) {
        batchProcess(list, next);
      } else if (next) {
        next();
      }
    })
  };
  totalList.forEach(o => {
    let item = articleDict[o.path];
    if (item) {
      let testObj = testItem(reg, item);
      if (item.content) {
        fitList.push(testObj);
      } else if (testObj.testType > 0) {
        ajaxList.push(item);
      } else {
        remainList.push(o);
      }
    }
  });
  if (isCommend) {
    return callback(ajaxList.concat(fitList).filter(o => o.testType > 0).sort((a, b) => b.searchWeight - a.searchWeight));
  }
  searchCallback(fitList);
  batchProcess(ajaxList, function () {
    batchProcess(remainList);
  })
  return remainList;
};

//搜索直达
const searchDirect = (word) => {
  let reg = m_search.getGlobalRegex(word);
  return articleList.filter(o => reg.test(o.title)).map(o => {
    let weight = 0;
    let item = {
      href: o.href,
      title: o.title.replace(reg, function ($0) {
        weight += $0.length;
        return '' + $0 + '';
      })
    };
    item.weight = weight
    return item;
  }).sort((a, b)=>b.weight - a.weight);
};

module.exports = {
  getName,
  isPreload,
  startTime,
  initArticle,
  catalogDict,
  articleDict,
  hasCatalog: (path) => !!catalogDict[path],
  hasArticle: (path) => !!articleDict[path],
  hasBook: (path) => !!bookDict[path],
  getCatalogMessage: (path) => catalogDict[path],
  getCatalogs: () => catalogList,
  getBooks: () => bookList,
  getTagArticles,
  getTags: () => tagList,
  getSidebarPath,
  getArticleList: () => articleList.map(o => articleDict[o.path]),
  getListByCatalog: getList(getCatalogArticles),
  getChildCatalog,
  getListByTag: getList(getTagArticles),
  getArticleContent: (path) => fetchContent([articleDict[path]])
    .then(() => articleDict[path]),
  searchDirect,
  searchList
};


text:
<?xml version="1.0" encoding="UTF-8"?>

<module rename-to='globalization'>

    <inherits name='com.florianf.gwtcordova.GwtCordova'/>

    <source path='client/plugin/globalization'/>

</module>