text:
package org.cometd.oort;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.junit.Assert;
import org.junit.Test;

public class OortServiceTest extends AbstractOortObjectTest
{
    public OortServiceTest(String serverTransport)
    {
        super(serverTransport);
    }

    @Test
    public void testActionIsForwarded() throws Exception
    {
        CountDownLatch latch1 = new CountDownLatch(1);
        Service service1 = new Service(oort1, latch1);
        service1.start();
        CountDownLatch latch2 = new CountDownLatch(1);
        Service service2 = new Service(oort2, latch2);
        service2.start();

        Assert.assertTrue(service1.perform(oort2.getURL(), oort1.getURL()));
        Assert.assertTrue(latch1.await(5, TimeUnit.SECONDS));
        Assert.assertTrue(service1.result);
        Assert.assertNull(service1.failure);

        Assert.assertTrue(service2.perform(oort2.getURL(), oort2.getURL()));
        Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
        Assert.assertTrue(service2.result);
        Assert.assertNull(service2.failure);

        service2.stop();
        service1.stop();
    }

    @Test
    public void testActionIsNotForwardedForUnknownURL() throws Exception
    {
        Service service1 = new Service(oort1, null);
        service1.start();

        Assert.assertFalse(service1.perform("unknownURL", "context1"));

        service1.stop();
    }

    @Test
    public void testActionIsBroadcast() throws Exception
    {
        CountDownLatch latch1 = new CountDownLatch(1);
        BroadcastService service1 = new BroadcastService(oort1, latch1);
        CountDownLatch latch2 = new CountDownLatch(1);
        BroadcastService service2 = new BroadcastService(oort2, latch2);
        String channelName = service1.getBroadcastChannelName();
        CometSubscriptionListener listener1 = new CometSubscriptionListener(channelName, 1);
        oort1.getBayeuxServer().addListener(listener1);
        CometSubscriptionListener listener2 = new CometSubscriptionListener(channelName, 1);
        oort2.getBayeuxServer().addListener(listener2);
        service1.start();
        // Wait for node1 to be subscribed on node2
        Assert.assertTrue(listener2.await(5, TimeUnit.SECONDS));
        service2.start();
        // Wait for node2 to be subscribed on node1
        Assert.assertTrue(listener1.await(5, TimeUnit.SECONDS));

        // Broadcast to all services, only one will reply
        String replier = oort2.getURL();
        Assert.assertTrue(service1.perform(null, replier, "context"));
        Assert.assertTrue(latch1.await(5, TimeUnit.SECONDS));
        Assert.assertTrue(service1.result);
        Assert.assertNull(service1.failure);

        // Send to the wrong service, ignore must be converted to failure
        String target = oort1.getURL();
        replier = oort2.getURL();
        Assert.assertTrue(service2.perform(target, replier, "context"));
        Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
        Assert.assertNull(service2.result);
        Assert.assertNotNull(service2.failure);

        service2.stop();
        service1.stop();
    }

    @Test
    public void testActionFailsOnRuntimeException() throws Exception
    {
        CountDownLatch latch1 = new CountDownLatch(1);
        Service service1 = new Service(oort1, latch1)
        {
            @Override
            protected Result<Boolean> onForward(Request request)
            {
                throw new NullPointerException();
            }
        };
        service1.start();
        CountDownLatch latch2 = new CountDownLatch(1);
        Service service2 = new Service(oort2, latch2)
        {
            @Override
            protected Result<Boolean> onForward(Request request)
            {
                throw new NullPointerException();
            }
        };
        service2.start();

        Assert.assertTrue(service1.perform(oort2.getURL(), oort1.getURL()));
        Assert.assertTrue(latch1.await(5, TimeUnit.SECONDS));
        Assert.assertNull(service1.result);
        Assert.assertEquals(NullPointerException.class.getName(), service1.failure);

        Assert.assertTrue(service2.perform(oort2.getURL(), oort2.getURL()));
        Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
        Assert.assertNull(service2.result);
        Assert.assertEquals(NullPointerException.class.getName(), service2.failure);

        service2.stop();
        service1.stop();
    }

    @Test
    public void testActionFailsOnFailure() throws Exception
    {
        final String failure = "failure";
        CountDownLatch latch1 = new CountDownLatch(1);
        Service service1 = new Service(oort1, latch1)
        {
            @Override
            protected Result<Boolean> onForward(Request request)
            {
                return Result.failure(failure);
            }
        };
        service1.start();
        CountDownLatch latch2 = new CountDownLatch(1);
        Service service2 = new Service(oort2, latch2)
        {
            @Override
            protected Result<Boolean> onForward(Request request)
            {
                return Result.failure(failure);
            }
        };
        service2.start();

        Assert.assertTrue(service1.perform(oort2.getURL(), oort1.getURL()));
        Assert.assertTrue(latch1.await(5, TimeUnit.SECONDS));
        Assert.assertNull(service1.result);
        Assert.assertEquals(failure, service1.failure);

        Assert.assertTrue(service2.perform(oort2.getURL(), oort2.getURL()));
        Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
        Assert.assertNull(service2.result);
        Assert.assertEquals(failure, service2.failure);

        service2.stop();
        service1.stop();
    }

    @Test
    public void testActionBroadcastTimeout() throws Exception
    {
        long timeout = 1000;
        CountDownLatch latch1 = new CountDownLatch(1);
        ExpireService service1 = new ExpireService(oort1, latch1)
        {
            @Override
            protected Result<Void> onForward(Request request)
            {
                return Result.ignore(null);
            }
        };
        service1.setTimeout(timeout);
        CountDownLatch latch2 = new CountDownLatch(1);
        ExpireService service2 = new ExpireService(oort2, latch2)
        {
            @Override
            protected Result<Void> onForward(Request request)
            {
                return Result.ignore(null);
            }
        };
        service2.setTimeout(timeout);
        String channelName = service1.getBroadcastChannelName();
        CometSubscriptionListener listener1 = new CometSubscriptionListener(channelName, 1);
        oort1.getBayeuxServer().addListener(listener1);
        CometSubscriptionListener listener2 = new CometSubscriptionListener(channelName, 1);
        oort2.getBayeuxServer().addListener(listener2);
        service1.start();
        // Wait for node1 to be subscribed on node2
        Assert.assertTrue(listener2.await(5, TimeUnit.SECONDS));
        service2.start();
        // Wait for node2 to be subscribed on node1
        Assert.assertTrue(listener1.await(5, TimeUnit.SECONDS));

        Assert.assertTrue(service1.perform(null));
        Assert.assertTrue(latch1.await(2 * timeout, TimeUnit.MILLISECONDS));

        Assert.assertTrue(service2.perform(null));
        Assert.assertTrue(latch2.await(2 * timeout, TimeUnit.MILLISECONDS));
    }

    @Test
    public void testActionForwardTimeout() throws Exception
    {
        final long timeout = 1000;
        CountDownLatch latch1 = new CountDownLatch(1);
        ExpireService service1 = new ExpireService(oort1, latch1)
        {
            @Override
            protected Result<Void> onForward(Request request)
            {
                try
                {
                    TimeUnit.MILLISECONDS.sleep(2 * timeout);
                    return Result.success(null);
                }
                catch (InterruptedException x)
                {
                    return Result.failure(null);
                }
            }
        };
        service1.setTimeout(timeout);
        service1.start();
        CountDownLatch latch2 = new CountDownLatch(1);
        ExpireService service2 = new ExpireService(oort2, latch2)
        {
            @Override
            protected Result<Void> onForward(Request request)
            {
                try
                {
                    TimeUnit.MILLISECONDS.sleep(2 * timeout);
                    return Result.success(null);
                }
                catch (InterruptedException x)
                {
                    return Result.failure(null);
                }
            }
        };
        service2.setTimeout(timeout);
        service2.start();

        Assert.assertTrue(service1.perform(oort2.getURL()));
        Assert.assertTrue(latch1.await(3 * timeout, TimeUnit.MILLISECONDS));

        TimeUnit.MILLISECONDS.sleep(2 * timeout);

        Assert.assertTrue(service2.perform(oort2.getURL()));
        Assert.assertTrue(latch2.await(3 * timeout, TimeUnit.MILLISECONDS));

        // Allow last perform to complete without exceptions
        TimeUnit.MILLISECONDS.sleep(2 * timeout);
    }

    private static class Service extends OortService<Boolean, String>
    {
        private final CountDownLatch latch;
        private volatile String context;
        private volatile Boolean result;
        private volatile Object failure;

        private Service(Oort oort, CountDownLatch latch)
        {
            super(oort, "test");
            this.latch = latch;
        }

        public boolean perform(String oortURL, String context)
        {
            this.context = context;
            return forward(oortURL, oortURL, context);
        }

        @Override
        protected Result<Boolean> onForward(Request request)
        {
            if (request.isLocal())
                Assert.assertEquals(context, request.getOortURL());
            return Result.success(getOort().getURL().equals(request.getData()));
        }

        @Override
        protected void onForwardSucceeded(Boolean result, String context)
        {
            Assert.assertSame(this.context, context);
            this.result = result;
            latch.countDown();
        }

        @Override
        protected void onForwardFailed(Object failure, String context)
        {
            Assert.assertSame(this.context, context);
            this.failure = failure;
            latch.countDown();
        }
    }

    private static class BroadcastService extends OortService<Boolean, String>
    {
        private final CountDownLatch latch;
        private volatile String context;
        private volatile Boolean result;
        private volatile Object failure;

        private BroadcastService(Oort oort, CountDownLatch latch)
        {
            super(oort, "test");
            this.latch = latch;
        }

        public String getBroadcastChannelName()
        {
            return "/oort/service/" + getName();
        }

        public boolean perform(String oortURL, String parameter, String context)
        {
            this.context = context;
            return forward(oortURL, parameter, context);
        }

        @Override
        protected Result<Boolean> onForward(Request request)
        {
            if (!request.isLocal() && getOort().getURL().equals(request.getData()))
                return Result.success(true);
            else
                return Result.ignore(false);
        }

        @Override
        protected void onForwardSucceeded(Boolean result, String context)
        {
            Assert.assertSame(this.context, context);
            this.result = result;
            latch.countDown();
        }

        @Override
        protected void onForwardFailed(Object failure, String context)
        {
            Assert.assertSame(this.context, context);
            this.failure = failure;
            latch.countDown();
        }
    }

    private abstract static class ExpireService extends OortService<Void, Void>
    {
        private final CountDownLatch latch;

        private ExpireService(Oort oort, CountDownLatch latch)
        {
            super(oort, "test");
            this.latch = latch;
        }

        public String getBroadcastChannelName()
        {
            return "/oort/service/" + getName();
        }

        public boolean perform(String oortURL)
        {
            return forward(oortURL, null, null);
        }

        @Override
        protected void onForwardSucceeded(Void result, Void context)
        {
        }

        @Override
        protected void onForwardFailed(Object failure, Void context)
        {
            if (failure instanceof TimeoutException)
                latch.countDown();
        }
    }
}


text:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />

    <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
    <script src="../../../web-animations-js/web-animations-next.min.js"></script>
    <script src="../../../web-component-tester/browser.js"></script>

    <link rel="import" href="../../modal/view.html" />
  </head>
  <body>
    <test-fixture id="modal">
      <template>
        <modal-clab></modal-clab>
      </template>
    </test-fixture>

    <script>
      describe('<modal-clab>', function () {
        var modal;

        beforeEach(function () {
          modal = fixture('modal');
        });

        context('Test Properties', function () {
          it('default properties', function (done) {
            expect(modal.visible).to.equal(false);
            expect(modal.title).to.equal('Modal title');
            expect(modal.primary).to.be.undefined;
            expect(modal.secondary).to.be.undefined;
            expect(modal.content).to.equal(null);

            done();
          });
        });

        context('Test DOM Bindings', function () {
          it('Check visible', function (done) {
            modal.visible = true;

            setTimeout(function () {
              expect(modal.querySelector('.modal-overlay')).to.not.be.undefined;

              done();
            }, 50);
          });

          it('Check title', function (done) {
            var title = 'A new title';
            modal.visible = true;
            modal.title = title;

            setTimeout(function () {
              expect(modal.querySelector('.modal-title').innerText).to.equal(
                title
              );

              done();
            }, 50);
          });

          it('Check primary & secondary', function (done) {
            var pri = 'this is first';
            var sec = 'this is second';
            var thi = 'this is third';
            modal.visible = true;
            modal.primary = pri;
            modal.secondary = sec;
            modal.warningBtn = thi;

            setTimeout(function () {
              expect(
                modal.querySelector('.btn.primary').innerText.trim()
              ).to.equal(pri);
              expect(
                modal.querySelector('.btn.secondary').innerText.trim()
              ).to.equal(sec);
              expect(
                modal.querySelector('.btn.third').innerText.trim()
              ).to.equal(thi);

              done();
            }, 50);
          });

          it('Check content', function (done) {
            var str = 'A new content';
            modal.visible = true;
            modal.content = str;

            setTimeout(function () {
              expect(modal.querySelector('.modal-body p').innerText).to.equal(
                str
              );

              done();
            }, 50);
          });
        });

        context('Test Events', function () {
          it('Closing the modal on-click', function (done) {
            modal.visible = true;

            setTimeout(function () {
              var evt = new Event('click');
              modal.querySelector('.close-overlay').dispatchEvent(evt);
              expect(modal.visible).to.equal(false);

              done();
            }, 50);
          });
        });
      });
    </script>
  </body>
</html>

redpajama_set_name: RedPajamaGithub


text:
module Mongoid::Globalize
  module Methods
    delegate :translated_locales, :to => :translations

    # Reader for adapter, where translations stashing during lifecicle. At first
    # use creates new one.
    # Return: Mongoid::Globalize::Adapter
    def globalize
      @globalize ||= Adapter.new(self)
    end

    # The most trouble method of Mongoid::Globalize :-(
    # Extends reader for @attributes. Mixes translated attributes to Mongoid
    # @attributes.
    # Return: Hash
    def attributes
      unless @stop_merging_translated_attributes || @attributes.frozen?
        @attributes.merge! translated_attributes
      end
      super
    end

    # Extends Mongoid::Document's method +process+. Pocesses given attributes in
    # consideration of possible :locale key. Used by Mongoid for all attribute-
    # related operations, such as +create+, +update+ etc.
    # Param: Hash of attributes
    # Other params will be transmitted into Mongoid::Document's method +process+
    # as is.
    def process(attributes, *args)
      with_given_locale(attributes) { super }
    end

    # Extends Mongoid::Document's method +write_attribute+. If writed attribute
    # is translateble, it is placed into adapter's stash.
    # Param: String or Symbol - name of attribute
    # Param: Object - value of attribute
    # Param: Hash of options
    def write_attribute(name, value, options = {})
      if translated?(name)
        options = {:locale => nil}.merge(options)
        access = name.to_s
        unless attributes[access] == value || attribute_changed?(access)
          attribute_will_change! access
        end
        @translated_attributes[access] = value
        the_locale = options[:locale] || Mongoid::Globalize.locale
        self.translations.reject!{ |t| t.new_record? && t.locale != the_locale } if self.class.fallbacks_for_empty_translations
        globalize.write(the_locale, name, value)
      else
        super(name, value)
      end
    end

    # Extends Mongoid::Document's method +read_attribute+. If writed attribute
    # is translateble, it is readed from adapter's stash.
    # Param: String or Symbol - name of attribute
    # Param: Hash of options
    # Return: Object - value of attribute
    def read_attribute(name, options = {})
      options = {:translated => true, :locale => nil}.merge(options)
      if translated?(name) and options[:translated]
        globalize.fetch(options[:locale] || Mongoid::Globalize.locale, name)
      else
        super(name)
      end
    end

    # TODO
    def remove_attribute(name)
      super name
    end

    # Mongoid documents haven't attribute_names method, so I replace +super+
    # with +@attributes.keys.sort+. So this method returns only translated and
    # existing attribute names (but not all available names as in AR or G3)
    def attribute_names
      translated_attribute_names.map(&:to_s) + @attributes.keys.sort
    end

    # Checks whether field with given name is translated field.
    # Param String or Symbol
    # Returns true or false
    def translated?(name)
      self.class.translated?(name)
    end

    # Returns translations for current locale. Is used for initial mixing into
    # @attributes hash. Actual translations are in @translated_attributes hash.
    # Return Hash
    def translated_attributes
      @translated_attributes ||= translated_attribute_names.inject({}) do |attrs, name|
        attrs.merge(name.to_s => translation.send(name))
      end
    end

    # TODO:
    def untranslated_attributes
      attrs = {}
      attribute_names.each do |name|
        attrs[name] = read_attribute(name, {:translated => false})
      end
      attrs
    end

    # Updates fields separately for each given locale
    #     post.set_translations(
    #       :en => { :title => "updated title" },
    #       :de => { :content => "geänderter Inhalt" }
    #     )
    # Param: Hash, where keys are locales and values are Hashes of name-value
    # pairs for fields.
    def set_translations(options)
      options.keys.each do |locale|
        translation = translation_for(locale) || translations.build(:locale => locale.to_s)
        translation.update_attributes!(options[locale])
      end
    end

    # Extends Mongoid::Document's method +reload+. Resets all translation
    # changes.
    def reload
      translated_attribute_names.each { |name| @attributes.delete(name.to_s) }
      globalize.reset
      super
    end

    # Extends Mongoid::Document's method +clone+. Adds to cloned object all
    # translations from original object.
    def clone
      obj = super
      return obj unless respond_to?(:translated_attribute_names)
      obj.instance_variable_set(:@globalize, nil )
      each_locale_and_translated_attribute do |locale, name|
        obj.globalize.write(locale, name, globalize.fetch(locale, name) )
      end
      return obj
    end

    # Returns instance of Translation for current locale.
    def translation
      translation_for(Mongoid::Globalize.locale)
    end

    # Returns instance of Translation for given locale.
    # Param String or Symbol
    def translation_for(locale)
      @translation_caches ||= {}
      # Need to temporary switch of merging, because #translations uses
      # #attributes method too, to avoid stack level too deep error.
      @stop_merging_translated_attributes = true
      unless @translation_caches[locale]
        _translation = translations.find_by_locale(locale)
        _translation ||= translations.build(:locale => locale)
        @translation_caches[locale] = _translation
      end
      @stop_merging_translated_attributes = false
      @translation_caches[locale]
    end

  protected
    # Executes given block for each locale and translated attribute name for
    # this document.
    def each_locale_and_translated_attribute
      used_locales.each do |locale|
        translated_attribute_names.each do |name|
          yield locale, name
        end
      end
    end

    # Return Array with locales, used for translation of this document
    def used_locales
      locales = globalize.stash.keys.concat(globalize.stash.keys).concat(translations.translated_locales)
      locales.uniq!
      locales
    end

    # Before save callback. Cleans @attributes hash from translated attributes
    # and prepares them for persisting.
    def prepare_translations!
      @stop_merging_translated_attributes = true
      translated_attribute_names.each do |name|
        @attributes.delete name.to_s
        @changed_attributes.delete name.to_s if @changed_attributes
      end
      globalize.prepare_translations!
    end

    # After save callback. Reset some values.
    def clear_translations!
      @translation_caches = {}
      @stop_merging_translated_attributes = nil
    end

    # Detects locale in given attributes and executes given block for it.
    # Param: Hash of attributes
    # Param: Proc
    def with_given_locale(attributes, &block)
      attributes.symbolize_keys! if attributes.respond_to?(:symbolize_keys!)
      if locale = attributes.try(:delete, :locale)
        Mongoid::Globalize.with_locale(locale, &block)
      else
        yield
      end
    end
  end
end


text:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.rgu5android.application.locker"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="22" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Material" >
        <activity
            android:name="com.rgu5android.application.locker.activity.ActivityInstructionManual"
            android:configChanges="keyboardHidden"
            android:label="@string/instruction_manual"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="com.rgu5android.application.locker.activity.ActivityManageApplication"
            android:configChanges="keyboardHidden"
            android:label="@string/manage_apps"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="com.rgu5android.application.locker.activity.ActivitySetPassword"
            android:configChanges="keyboardHidden"
            android:label="@string/set_password"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="com.rgu5android.application.locker.activity.ActivityPasswordChecker"
            android:configChanges="keyboardHidden"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.rgu5android.application.locker.activity.ActivityAboutUs"
            android:configChanges="keyboardHidden"
            android:label="@string/about_us"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="com.rgu5android.application.locker.activity.ActivityLockedApplication"
            android:configChanges="keyboardHidden"
            android:label="@string/locked_apps"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="com.rgu5android.application.locker.activity.ActivityAppLocker"
            android:configChanges="keyboardHidden"
            android:excludeFromRecents="true"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        </activity>

        <receiver android:name="com.rgu5android.application.locker.broadcast.BroadcastReceiverAppLocker" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.BATTERY_CHANGED" />
            </intent-filter>
        </receiver>

        <service android:name="com.rgu5android.application.locker.service.ServiceAppLocker" />
    </application>

</manifest>


text:
<?php

namespace SwaggerValidator\Common;

/**
 * Description of ReferenceCollection
 *
 * @author Nicolas JUHEL<swaggervalidator@nabbar.com>
 * @version 1.0.0
 */
class CollectionFile extends \SwaggerValidator\Common\Collection
{

    const ID_PREFIX = 'file:';

    /**
     *
     * @var \SwaggerValidator\Common\CollectionFile
     */
    private static $instance;

    /**
     *
     * @var array
     */
    private static $fileIdList = array();

    /**
     * Private construct for singleton
     */
    private function __construct()
    {

    }

    /**
     *
     * @return \SwaggerValidator\Common\CollectionFile
     */
    public static function getInstance()
    {
        if (empty(self::$instance)) {
            self::$instance = new static();
        }

        return self::$instance;
    }

    /**
     * replace the singleton of this collection
     */
    public static function setInstance(\SwaggerValidator\Common\CollectionFile $instance)
    {
        self::$instance   = $instance;
        self::$fileIdList = array();
    }

    public static function pruneInstance()
    {
        self::$instance   = null;
        self::$fileIdList = array();
    }

    public function __isset($ref)
    {
        parent::__isset(self::getIdFromRef($ref));
    }

    public function __unset($ref)
    {
        parent::__unset(self::getIdFromRef($ref));
    }

    /**
     * Return the content of the reference as object or mixed data
     * @param string $fileLink
     * @return \SwaggerValidator\Common\ReferenceFile
     * @throws \SwaggerValidator\Exception
     */
    public function __get($fileLink)
    {

    }

    public function __set($ref, $value = null)
    {

    }

    /**
     * Var Export Method
     */
    protected function __storeData($key, $value = null)
    {
        if (property_exists($this, $key)) {
            $this->$key = $value;
        }
        else {
            parent::__storeData($key, $value);
        }
    }

    public static function __set_state(array $properties)
    {
        self::getInstance();

        foreach ($properties as $key => $value) {
            self::$instance->__storeData($key, $value);
        }

        return self::getInstance();
    }

    public function jsonSerialize()
    {
        return null;
    }

    public function serialize()
    {
        return null;
    }

    public function unserialize($data)
    {
        return null;
    }

    /**
     * Return the content of the reference as object or mixed data
     * @param string $fileLink
     * @return \SwaggerValidator\Common\ReferenceFile
     * @throws \SwaggerValidator\Exception
     */
    public function get(\SwaggerValidator\Common\Context $context, $fileLink)
    {
        if (empty($fileLink)) {
            $context->throwException('Cannot find file link from ref : ' . $fileLink, __FILE__, __LINE__);
        }

        $id = self::getIdFromRef($fileLink);

        if (!is_object(parent::__get($id))) {
            $this->set($context, $fileLink);
        }

        $context->logLoadFile(self::getRefFromId($id), __METHOD__, __LINE__);

        return parent::__get($id);
    }

    public function set(\SwaggerValidator\Common\Context $context, $ref, $value = null)
    {
        $id = self::getIdFromRef($ref);

        if ($id == $ref) {
            $ref = self::getRefFromId($id);
        }

        if (!is_object($value) || !($value instanceof \SwaggerValidator\Common\ReferenceFile)) {
            $value = new \SwaggerValidator\Common\ReferenceFile($context, $ref);
        }

        if (is_object($value) && ($value instanceof \SwaggerValidator\Common\ReferenceFile)) {
            $value->extractAllReference($context);
            return parent::__set($id, $value);
        }

        $context->throwException('Cannot register file from ref : ' . $ref, __FILE__, __LINE__);
    }

    public static function getReferenceFileLink($ref)
    {
        if (strpos($ref, '#') === false) {
            return $ref;
        }

        $fileLink = explode('#', $ref);
        array_pop($fileLink);
        return implode('#', $fileLink);
    }

    public static function getReferenceInnerPath($ref)
    {
        if (strpos($ref, '#') === false) {
            return;
        }

        $fileLink = explode('#', $ref);
        return array_pop($fileLink);
    }

    public static function getIdFromRef($fullRef)
    {
        if (substr($fullRef, 0, 3) === self::ID_PREFIX) {
            return $fullRef;
        }

        if (!is_array(self::$fileIdList)) {
            self::$fileIdList = array();
        }

        if (!array_key_exists($fullRef, self::$fileIdList)) {
            //self::$fileIdList[$fullRef] = uniqid(self::ID_PREFIX);
            self::$fileIdList[$fullRef] = self::ID_PREFIX . hash('sha256', $fullRef, false);
        }

        return self::$fileIdList[$fullRef];
    }

    public static function getRefFromId($id)
    {
        if (substr($id, 0, 3) !== self::ID_PREFIX) {
            return $id;
        }

        if (!is_array(self::$fileIdList)) {
            self::$fileIdList = array();
        }

        if (!in_array($id, self::$fileIdList)) {
            return null;
        }

        return array_search($id, self::$fileIdList);
    }

}


text:
package org.apache.hadoop.hbase.regionserver;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeepDeletedCells;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueTestUtil;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.exceptions.UnexpectedStateException;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdge;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.FSTableDescriptors;
import org.apache.hadoop.hbase.wal.WALFactory;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hbase.thirdparty.com.google.common.base.Joiner;
import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;

/** memstore test case */
@Category({RegionServerTests.class, MediumTests.class})
public class TestDefaultMemStore {

  @ClassRule
  public static final HBaseClassTestRule CLASS_RULE =
      HBaseClassTestRule.forClass(TestDefaultMemStore.class);

  private static final Logger LOG = LoggerFactory.getLogger(TestDefaultMemStore.class);
  @Rule public TestName name = new TestName();
  protected AbstractMemStore memstore;
  protected static final int ROW_COUNT = 10;
  protected static final int QUALIFIER_COUNT = ROW_COUNT;
  protected static final byte[] FAMILY = Bytes.toBytes("column");
  protected MultiVersionConcurrencyControl mvcc;
  protected AtomicLong startSeqNum = new AtomicLong(0);
  protected ChunkCreator chunkCreator;

  private String getName() {
    return this.name.getMethodName();
  }

  @Before
  public void setUp() throws Exception {
    internalSetUp();
    // no pool
    this.chunkCreator =
        ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
    this.memstore = new DefaultMemStore();
  }

  @AfterClass
  public static void tearDownClass() throws Exception {
    ChunkCreator.getInstance().clearChunkIds();
  }

  protected void internalSetUp() throws Exception {
    this.mvcc = new MultiVersionConcurrencyControl();
  }

  @Test
  public void testPutSameKey() {
    byte[] bytes = Bytes.toBytes(getName());
    KeyValue kv = new KeyValue(bytes, bytes, bytes, bytes);
    this.memstore.add(kv, null);
    byte[] other = Bytes.toBytes("somethingelse");
    KeyValue samekey = new KeyValue(bytes, bytes, bytes, other);
    this.memstore.add(samekey, null);
    Cell found = this.memstore.getActive().first();
    assertEquals(1, this.memstore.getActive().getCellsCount());
    assertTrue(Bytes.toString(found.getValueArray()), CellUtil.matchingValue(samekey, found));
  }

  @Test
  public void testPutSameCell() {
    byte[] bytes = Bytes.toBytes(getName());
    KeyValue kv = new KeyValue(bytes, bytes, bytes, bytes);
    MemStoreSizing sizeChangeForFirstCell = new NonThreadSafeMemStoreSizing();
    this.memstore.add(kv, sizeChangeForFirstCell);
    MemStoreSizing sizeChangeForSecondCell = new NonThreadSafeMemStoreSizing();
    this.memstore.add(kv, sizeChangeForSecondCell);
    // make sure memstore size increase won't double-count MSLAB chunk size
    assertEquals(Segment.getCellLength(kv), sizeChangeForFirstCell.getMemStoreSize().getDataSize());
    Segment segment = this.memstore.getActive();
    MemStoreLAB msLab = segment.getMemStoreLAB();
    if (msLab != null) {
      // make sure memstore size increased even when writing the same cell, if using MSLAB
      assertEquals(Segment.getCellLength(kv),
          sizeChangeForSecondCell.getMemStoreSize().getDataSize());
      // make sure chunk size increased even when writing the same cell, if using MSLAB
      if (msLab instanceof MemStoreLABImpl) {
        // since we add the chunkID at the 0th offset of the chunk and the
        // chunkid is an int we need to account for those 4 bytes
        assertEquals(2 * Segment.getCellLength(kv) + Bytes.SIZEOF_INT,
          ((MemStoreLABImpl) msLab).getCurrentChunk().getNextFreeOffset());
      }
    } else {
      // make sure no memstore size change w/o MSLAB
      assertEquals(0, sizeChangeForSecondCell.getMemStoreSize().getDataSize());
      assertEquals(0, sizeChangeForSecondCell.getMemStoreSize().getHeapSize());
    }
  }

  /**
   * Test memstore snapshot happening while scanning.
   * @throws IOException
   */
  @Test
  public void testScanAcrossSnapshot() throws IOException {
    int rowCount = addRows(this.memstore);
    List<KeyValueScanner> memstorescanners = this.memstore.getScanners(0);
    Scan scan = new Scan();
    List<Cell> result = new ArrayList<>();
    Configuration conf = HBaseConfiguration.create();
    ScanInfo scanInfo = new ScanInfo(conf, null, 0, 1, HConstants.LATEST_TIMESTAMP,
        KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, this.memstore.getComparator(), false);
    int count = 0;
    try (StoreScanner s = new StoreScanner(scan, scanInfo, null, memstorescanners)) {
      while (s.next(result)) {
        LOG.info(Objects.toString(result));
        count++;
        // Row count is same as column count.
        assertEquals(rowCount, result.size());
        result.clear();
      }
    }
    assertEquals(rowCount, count);
    for (KeyValueScanner scanner : memstorescanners) {
      scanner.close();
    }

    memstorescanners = this.memstore.getScanners(mvcc.getReadPoint());
    // Now assert can count same number even if a snapshot mid-scan.
    count = 0;
    try (StoreScanner s = new StoreScanner(scan, scanInfo, null, memstorescanners)) {
      while (s.next(result)) {
        LOG.info(Objects.toString(result));
        // Assert the stuff is coming out in right order.
        assertTrue(CellUtil.matchingRows(result.get(0), Bytes.toBytes(count)));
        count++;
        // Row count is same as column count.
        assertEquals(rowCount, result.size());
        if (count == 2) {
          this.memstore.snapshot();
          LOG.info("Snapshotted");
        }
        result.clear();
      }
    }
    assertEquals(rowCount, count);
    for (KeyValueScanner scanner : memstorescanners) {
      scanner.close();
    }
    memstorescanners = this.memstore.getScanners(mvcc.getReadPoint());
    // Assert that new values are seen in kvset as we scan.
    long ts = System.currentTimeMillis();
    count = 0;
    int snapshotIndex = 5;
    try (StoreScanner s = new StoreScanner(scan, scanInfo, null, memstorescanners)) {
      while (s.next(result)) {
        LOG.info(Objects.toString(result));
        // Assert the stuff is coming out in right order.
        assertTrue(CellUtil.matchingRows(result.get(0), Bytes.toBytes(count)));
        // Row count is same as column count.
        assertEquals("count=" + count + ", result=" + result, rowCount, result.size());
        count++;
        if (count == snapshotIndex) {
          MemStoreSnapshot snapshot = this.memstore.snapshot();
          this.memstore.clearSnapshot(snapshot.getId());
          // Added more rows into kvset. But the scanner wont see these rows.
          addRows(this.memstore, ts);
          LOG.info("Snapshotted, cleared it and then added values (which wont be seen)");
        }
        result.clear();
      }
    }
    assertEquals(rowCount, count);
  }

  /**
   * A simple test which verifies the 3 possible states when scanning across snapshot.
   * @throws IOException
   * @throws CloneNotSupportedException
   */
  @Test
  public void testScanAcrossSnapshot2() throws IOException, CloneNotSupportedException {
    // we are going to the scanning across snapshot with two kvs
    // kv1 should always be returned before kv2
    final byte[] one = Bytes.toBytes(1);
    final byte[] two = Bytes.toBytes(2);
    final byte[] f = Bytes.toBytes("f");
    final byte[] q = Bytes.toBytes("q");
    final byte[] v = Bytes.toBytes(3);

    final KeyValue kv1 = new KeyValue(one, f, q, v);
    final KeyValue kv2 = new KeyValue(two, f, q, v);

    // use case 1: both kvs in kvset
    this.memstore.add(kv1.clone(), null);
    this.memstore.add(kv2.clone(), null);
    verifyScanAcrossSnapshot2(kv1, kv2);

    // use case 2: both kvs in snapshot
    this.memstore.snapshot();
    verifyScanAcrossSnapshot2(kv1, kv2);

    // use case 3: first in snapshot second in kvset
    this.memstore = new DefaultMemStore();
    this.memstore.add(kv1.clone(), null);
    this.memstore.snapshot();
    this.memstore.add(kv2.clone(), null);
    verifyScanAcrossSnapshot2(kv1, kv2);
  }

  protected void verifyScanAcrossSnapshot2(KeyValue kv1, KeyValue kv2)
      throws IOException {
    List<KeyValueScanner> memstorescanners = this.memstore.getScanners(mvcc.getReadPoint());
    assertEquals(2, memstorescanners.size());
    final KeyValueScanner scanner0 = memstorescanners.get(0);
    final KeyValueScanner scanner1 = memstorescanners.get(1);
    scanner0.seek(KeyValueUtil.createFirstOnRow(HConstants.EMPTY_START_ROW));
    scanner1.seek(KeyValueUtil.createFirstOnRow(HConstants.EMPTY_START_ROW));
    Cell n0 = scanner0.next();
    Cell n1 = scanner1.next();
    assertTrue(kv1.equals(n0) || kv1.equals(n1));
    assertTrue(kv2.equals(n0)
        || kv2.equals(n1)
        || kv2.equals(scanner0.next())
        || kv2.equals(scanner1.next()));
    assertNull(scanner0.next());
    assertNull(scanner1.next());
  }

  protected void assertScannerResults(KeyValueScanner scanner, KeyValue[] expected)
      throws IOException {
    scanner.seek(KeyValueUtil.createFirstOnRow(new byte[]{}));
    List<Cell> returned = Lists.newArrayList();

    while (true) {
      Cell next = scanner.next();
      if (next == null) break;
      returned.add(next);
    }

    assertTrue(
        "Got:\n" + Joiner.on("\n").join(returned) +
        "\nExpected:\n" + Joiner.on("\n").join(expected),
        Iterables.elementsEqual(Arrays.asList(expected), returned));
    assertNull(scanner.peek());
  }

  @Test
  public void testMemstoreConcurrentControl() throws IOException {
    final byte[] row = Bytes.toBytes(1);
    final byte[] f = Bytes.toBytes("family");
    final byte[] q1 = Bytes.toBytes("q1");
    final byte[] q2 = Bytes.toBytes("q2");
    final byte[] v = Bytes.toBytes("value");

    MultiVersionConcurrencyControl.WriteEntry w =
        mvcc.begin();

    KeyValue kv1 = new KeyValue(row, f, q1, v);
    kv1.setSequenceId(w.getWriteNumber());
    memstore.add(kv1, null);

    KeyValueScanner s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{});

    mvcc.completeAndWait(w);

    s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{kv1});

    w = mvcc.begin();
    KeyValue kv2 = new KeyValue(row, f, q2, v);
    kv2.setSequenceId(w.getWriteNumber());
    memstore.add(kv2, null);

    s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{kv1});

    mvcc.completeAndWait(w);

    s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{kv1, kv2});
  }

  /**
   * Regression test for HBASE-2616, HBASE-2670.
   * When we insert a higher-memstoreTS version of a cell but with
   * the same timestamp, we still need to provide consistent reads
   * for the same scanner.
   */
  @Test
  public void testMemstoreEditsVisibilityWithSameKey() throws IOException {
    final byte[] row = Bytes.toBytes(1);
    final byte[] f = Bytes.toBytes("family");
    final byte[] q1 = Bytes.toBytes("q1");
    final byte[] q2 = Bytes.toBytes("q2");
    final byte[] v1 = Bytes.toBytes("value1");
    final byte[] v2 = Bytes.toBytes("value2");

    // INSERT 1: Write both columns val1
    MultiVersionConcurrencyControl.WriteEntry w =
        mvcc.begin();

    KeyValue kv11 = new KeyValue(row, f, q1, v1);
    kv11.setSequenceId(w.getWriteNumber());
    memstore.add(kv11, null);

    KeyValue kv12 = new KeyValue(row, f, q2, v1);
    kv12.setSequenceId(w.getWriteNumber());
    memstore.add(kv12, null);
    mvcc.completeAndWait(w);

    // BEFORE STARTING INSERT 2, SEE FIRST KVS
    KeyValueScanner s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{kv11, kv12});

    // START INSERT 2: Write both columns val2
    w = mvcc.begin();
    KeyValue kv21 = new KeyValue(row, f, q1, v2);
    kv21.setSequenceId(w.getWriteNumber());
    memstore.add(kv21, null);

    KeyValue kv22 = new KeyValue(row, f, q2, v2);
    kv22.setSequenceId(w.getWriteNumber());
    memstore.add(kv22, null);

    // BEFORE COMPLETING INSERT 2, SEE FIRST KVS
    s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{kv11, kv12});

    // COMPLETE INSERT 2
    mvcc.completeAndWait(w);

    // NOW SHOULD SEE NEW KVS IN ADDITION TO OLD KVS.
    // See HBASE-1485 for discussion about what we should do with
    // the duplicate-TS inserts
    s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{kv21, kv11, kv22, kv12});
  }

  /**
   * When we insert a higher-memstoreTS deletion of a cell but with
   * the same timestamp, we still need to provide consistent reads
   * for the same scanner.
   */
  @Test
  public void testMemstoreDeletesVisibilityWithSameKey() throws IOException {
    final byte[] row = Bytes.toBytes(1);
    final byte[] f = Bytes.toBytes("family");
    final byte[] q1 = Bytes.toBytes("q1");
    final byte[] q2 = Bytes.toBytes("q2");
    final byte[] v1 = Bytes.toBytes("value1");
    // INSERT 1: Write both columns val1
    MultiVersionConcurrencyControl.WriteEntry w =
        mvcc.begin();

    KeyValue kv11 = new KeyValue(row, f, q1, v1);
    kv11.setSequenceId(w.getWriteNumber());
    memstore.add(kv11, null);

    KeyValue kv12 = new KeyValue(row, f, q2, v1);
    kv12.setSequenceId(w.getWriteNumber());
    memstore.add(kv12, null);
    mvcc.completeAndWait(w);

    // BEFORE STARTING INSERT 2, SEE FIRST KVS
    KeyValueScanner s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{kv11, kv12});

    // START DELETE: Insert delete for one of the columns
    w = mvcc.begin();
    KeyValue kvDel = new KeyValue(row, f, q2, kv11.getTimestamp(),
        KeyValue.Type.DeleteColumn);
    kvDel.setSequenceId(w.getWriteNumber());
    memstore.add(kvDel, null);

    // BEFORE COMPLETING DELETE, SEE FIRST KVS
    s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{kv11, kv12});

    // COMPLETE DELETE
    mvcc.completeAndWait(w);

    // NOW WE SHOULD SEE DELETE
    s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    assertScannerResults(s, new KeyValue[]{kv11, kvDel, kv12});
  }

  private static class ReadOwnWritesTester extends Thread {
    static final int NUM_TRIES = 1000;

    final byte[] row;

    final byte[] f = Bytes.toBytes("family");
    final byte[] q1 = Bytes.toBytes("q1");

    final MultiVersionConcurrencyControl mvcc;
    final MemStore memstore;

    AtomicReference<Throwable> caughtException;

    public ReadOwnWritesTester(int id, MemStore memstore, MultiVersionConcurrencyControl mvcc,
        AtomicReference<Throwable> caughtException) {
      this.mvcc = mvcc;
      this.memstore = memstore;
      this.caughtException = caughtException;
      row = Bytes.toBytes(id);
    }

    @Override
    public void run() {
      try {
        internalRun();
      } catch (Throwable t) {
        caughtException.compareAndSet(null, t);
      }
    }

    private void internalRun() throws IOException {
      for (long i = 0; i < NUM_TRIES && caughtException.get() == null; i++) {
        MultiVersionConcurrencyControl.WriteEntry w =
            mvcc.begin();

        // Insert the sequence value (i)
        byte[] v = Bytes.toBytes(i);

        KeyValue kv = new KeyValue(row, f, q1, i, v);
        kv.setSequenceId(w.getWriteNumber());
        memstore.add(kv, null);
        mvcc.completeAndWait(w);

        // Assert that we can read back
        KeyValueScanner s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
        s.seek(kv);

        Cell ret = s.next();
        assertNotNull("Didnt find own write at all", ret);
        assertEquals("Didnt read own writes",
                     kv.getTimestamp(), ret.getTimestamp());
      }
    }
  }

  @Test
  public void testReadOwnWritesUnderConcurrency() throws Throwable {
    int NUM_THREADS = 8;

    ReadOwnWritesTester threads[] = new ReadOwnWritesTester[NUM_THREADS];
    AtomicReference<Throwable> caught = new AtomicReference<>();

    for (int i = 0; i < NUM_THREADS; i++) {
      threads[i] = new ReadOwnWritesTester(i, memstore, mvcc, caught);
      threads[i].start();
    }

    for (int i = 0; i < NUM_THREADS; i++) {
      threads[i].join();
    }

    if (caught.get() != null) {
      throw caught.get();
    }
  }

  /**
   * Test memstore snapshots
   * @throws IOException
   */
  @Test
  public void testSnapshotting() throws IOException {
    final int snapshotCount = 5;
    // Add some rows, run a snapshot. Do it a few times.
    for (int i = 0; i < snapshotCount; i++) {
      addRows(this.memstore);
      runSnapshot(this.memstore);
      assertEquals("History not being cleared", 0, this.memstore.getSnapshot().getCellsCount());
    }
  }

  @Test
  public void testMultipleVersionsSimple() throws Exception {
    DefaultMemStore m = new DefaultMemStore(new Configuration(), CellComparatorImpl.COMPARATOR);
    byte [] row = Bytes.toBytes("testRow");
    byte [] family = Bytes.toBytes("testFamily");
    byte [] qf = Bytes.toBytes("testQualifier");
    long [] stamps = {1,2,3};
    byte [][] values = {Bytes.toBytes("value0"), Bytes.toBytes("value1"),
        Bytes.toBytes("value2")};
    KeyValue key0 = new KeyValue(row, family, qf, stamps[0], values[0]);
    KeyValue key1 = new KeyValue(row, family, qf, stamps[1], values[1]);
    KeyValue key2 = new KeyValue(row, family, qf, stamps[2], values[2]);

    m.add(key0, null);
    m.add(key1, null);
    m.add(key2, null);

    assertTrue("Expected memstore to hold 3 values, actually has " +
        m.getActive().getCellsCount(), m.getActive().getCellsCount() == 3);
  }

  //////////////////////////////////////////////////////////////////////////////
  // Get tests
  //////////////////////////////////////////////////////////////////////////////

  /** Test getNextRow from memstore
   * @throws InterruptedException
   */
  @Test
  public void testGetNextRow() throws Exception {
    addRows(this.memstore);
    // Add more versions to make it a little more interesting.
    Thread.sleep(1);
    addRows(this.memstore);
    Cell closestToEmpty = ((DefaultMemStore) this.memstore).getNextRow(KeyValue.LOWESTKEY);
    assertTrue(CellComparatorImpl.COMPARATOR.compareRows(closestToEmpty,
        new KeyValue(Bytes.toBytes(0), System.currentTimeMillis())) == 0);
    for (int i = 0; i < ROW_COUNT; i++) {
      Cell nr = ((DefaultMemStore) this.memstore).getNextRow(new KeyValue(Bytes.toBytes(i),
          System.currentTimeMillis()));
      if (i + 1 == ROW_COUNT) {
        assertNull(nr);
      } else {
        assertTrue(CellComparatorImpl.COMPARATOR.compareRows(nr,
            new KeyValue(Bytes.toBytes(i + 1), System.currentTimeMillis())) == 0);
      }
    }
    //starting from each row, validate results should contain the starting row
    Configuration conf = HBaseConfiguration.create();
    for (int startRowId = 0; startRowId < ROW_COUNT; startRowId++) {
      ScanInfo scanInfo =
          new ScanInfo(conf, FAMILY, 0, 1, Integer.MAX_VALUE, KeepDeletedCells.FALSE,
              HConstants.DEFAULT_BLOCKSIZE, 0, this.memstore.getComparator(), false);
      try (InternalScanner scanner =
          new StoreScanner(new Scan().withStartRow(Bytes.toBytes(startRowId)), scanInfo, null,
              memstore.getScanners(0))) {
        List<Cell> results = new ArrayList<>();
        for (int i = 0; scanner.next(results); i++) {
          int rowId = startRowId + i;
          Cell left = results.get(0);
          byte[] row1 = Bytes.toBytes(rowId);
          assertTrue("Row name",
            CellComparatorImpl.COMPARATOR.compareRows(left, row1, 0, row1.length) == 0);
          assertEquals("Count of columns", QUALIFIER_COUNT, results.size());
          List<Cell> row = new ArrayList<>();
          for (Cell kv : results) {
            row.add(kv);
          }
          isExpectedRowWithoutTimestamps(rowId, row);
          // Clear out set. Otherwise row results accumulate.
          results.clear();
        }
      }
    }
  }

  @Test
  public void testGet_memstoreAndSnapShot() throws IOException {
    byte [] row = Bytes.toBytes("testrow");
    byte [] fam = Bytes.toBytes("testfamily");
    byte [] qf1 = Bytes.toBytes("testqualifier1");
    byte [] qf2 = Bytes.toBytes("testqualifier2");
    byte [] qf3 = Bytes.toBytes("testqualifier3");
    byte [] qf4 = Bytes.toBytes("testqualifier4");
    byte [] qf5 = Bytes.toBytes("testqualifier5");
    byte [] val = Bytes.toBytes("testval");

    //Setting up memstore
    memstore.add(new KeyValue(row, fam, qf1, val), null);
    memstore.add(new KeyValue(row, fam, qf2, val), null);
    memstore.add(new KeyValue(row, fam, qf3, val), null);
    //Creating a snapshot
    memstore.snapshot();
    assertEquals(3, memstore.getSnapshot().getCellsCount());
    //Adding value to "new" memstore
    assertEquals(0, memstore.getActive().getCellsCount());
    memstore.add(new KeyValue(row, fam ,qf4, val), null);
    memstore.add(new KeyValue(row, fam ,qf5, val), null);
    assertEquals(2, memstore.getActive().getCellsCount());
  }

  //////////////////////////////////////////////////////////////////////////////
  // Delete tests
  //////////////////////////////////////////////////////////////////////////////
  @Test
  public void testGetWithDelete() throws IOException {
    byte [] row = Bytes.toBytes("testrow");
    byte [] fam = Bytes.toBytes("testfamily");
    byte [] qf1 = Bytes.toBytes("testqualifier");
    byte [] val = Bytes.toBytes("testval");

    long ts1 = System.nanoTime();
    KeyValue put1 = new KeyValue(row, fam, qf1, ts1, val);
    long ts2 = ts1 + 1;
    KeyValue put2 = new KeyValue(row, fam, qf1, ts2, val);
    long ts3 = ts2 + 1;
    KeyValue put3 = new KeyValue(row, fam, qf1, ts3, val);
    memstore.add(put1, null);
    memstore.add(put2, null);
    memstore.add(put3, null);

    assertEquals(3, memstore.getActive().getCellsCount());

    KeyValue del2 = new KeyValue(row, fam, qf1, ts2, KeyValue.Type.Delete, val);
    memstore.add(del2, null);

    List<Cell> expected = new ArrayList<>();
    expected.add(put3);
    expected.add(del2);
    expected.add(put2);
    expected.add(put1);

    assertEquals(4, memstore.getActive().getCellsCount());
    int i = 0;
    for(Cell cell : memstore.getActive().getCellSet()) {
      assertEquals(expected.get(i++), cell);
    }
  }

  @Test
  public void testGetWithDeleteColumn() throws IOException {
    byte [] row = Bytes.toBytes("testrow");
    byte [] fam = Bytes.toBytes("testfamily");
    byte [] qf1 = Bytes.toBytes("testqualifier");
    byte [] val = Bytes.toBytes("testval");

    long ts1 = System.nanoTime();
    KeyValue put1 = new KeyValue(row, fam, qf1, ts1, val);
    long ts2 = ts1 + 1;
    KeyValue put2 = new KeyValue(row, fam, qf1, ts2, val);
    long ts3 = ts2 + 1;
    KeyValue put3 = new KeyValue(row, fam, qf1, ts3, val);
    memstore.add(put1, null);
    memstore.add(put2, null);
    memstore.add(put3, null);

    assertEquals(3, memstore.getActive().getCellsCount());

    KeyValue del2 =
      new KeyValue(row, fam, qf1, ts2, KeyValue.Type.DeleteColumn, val);
    memstore.add(del2, null);

    List<Cell> expected = new ArrayList<>();
    expected.add(put3);
    expected.add(del2);
    expected.add(put2);
    expected.add(put1);

    assertEquals(4, memstore.getActive().getCellsCount());
    int i = 0;
    for (Cell cell : memstore.getActive().getCellSet()) {
      assertEquals(expected.get(i++), cell);
    }
  }

  @Test
  public void testGetWithDeleteFamily() throws IOException {
    byte [] row = Bytes.toBytes("testrow");
    byte [] fam = Bytes.toBytes("testfamily");
    byte [] qf1 = Bytes.toBytes("testqualifier1");
    byte [] qf2 = Bytes.toBytes("testqualifier2");
    byte [] qf3 = Bytes.toBytes("testqualifier3");
    byte [] val = Bytes.toBytes("testval");
    long ts = System.nanoTime();

    KeyValue put1 = new KeyValue(row, fam, qf1, ts, val);
    KeyValue put2 = new KeyValue(row, fam, qf2, ts, val);
    KeyValue put3 = new KeyValue(row, fam, qf3, ts, val);
    KeyValue put4 = new KeyValue(row, fam, qf3, ts+1, val);

    memstore.add(put1, null);
    memstore.add(put2, null);
    memstore.add(put3, null);
    memstore.add(put4, null);

    KeyValue del =
      new KeyValue(row, fam, null, ts, KeyValue.Type.DeleteFamily, val);
    memstore.add(del, null);

    List<Cell> expected = new ArrayList<>();
    expected.add(del);
    expected.add(put1);
    expected.add(put2);
    expected.add(put4);
    expected.add(put3);

    assertEquals(5, memstore.getActive().getCellsCount());
    int i = 0;
    for (Cell cell : memstore.getActive().getCellSet()) {
      assertEquals(expected.get(i++), cell);
    }
  }

  @Test
  public void testKeepDeleteInmemstore() {
    byte [] row = Bytes.toBytes("testrow");
    byte [] fam = Bytes.toBytes("testfamily");
    byte [] qf = Bytes.toBytes("testqualifier");
    byte [] val = Bytes.toBytes("testval");
    long ts = System.nanoTime();
    memstore.add(new KeyValue(row, fam, qf, ts, val), null);
    KeyValue delete = new KeyValue(row, fam, qf, ts, KeyValue.Type.Delete, val);
    memstore.add(delete, null);
    assertEquals(2, memstore.getActive().getCellsCount());
    assertEquals(delete, memstore.getActive().first());
  }

  @Test
  public void testRetainsDeleteVersion() throws IOException {
    // add a put to memstore
    memstore.add(KeyValueTestUtil.create("row1", "fam", "a", 100, "dont-care"), null);

    // now process a specific delete:
    KeyValue delete = KeyValueTestUtil.create(
        "row1", "fam", "a", 100, KeyValue.Type.Delete, "dont-care");
    memstore.add(delete, null);

    assertEquals(2, memstore.getActive().getCellsCount());
    assertEquals(delete, memstore.getActive().first());
  }

  @Test
  public void testRetainsDeleteColumn() throws IOException {
    // add a put to memstore
    memstore.add(KeyValueTestUtil.create("row1", "fam", "a", 100, "dont-care"), null);

    // now process a specific delete:
    KeyValue delete = KeyValueTestUtil.create("row1", "fam", "a", 100,
        KeyValue.Type.DeleteColumn, "dont-care");
    memstore.add(delete, null);

    assertEquals(2, memstore.getActive().getCellsCount());
    assertEquals(delete, memstore.getActive().first());
  }

  @Test
  public void testRetainsDeleteFamily() throws IOException {
    // add a put to memstore
    memstore.add(KeyValueTestUtil.create("row1", "fam", "a", 100, "dont-care"), null);

    // now process a specific delete:
    KeyValue delete = KeyValueTestUtil.create("row1", "fam", "a", 100,
        KeyValue.Type.DeleteFamily, "dont-care");
    memstore.add(delete, null);

    assertEquals(2, memstore.getActive().getCellsCount());
    assertEquals(delete, memstore.getActive().first());
  }

  //////////////////////////////////////////////////////////////////////////////
  // Helpers
  //////////////////////////////////////////////////////////////////////////////
  private static byte [] makeQualifier(final int i1, final int i2){
    return Bytes.toBytes(Integer.toString(i1) + ";" +
        Integer.toString(i2));
  }

  /**
   * Add keyvalues with a fixed memstoreTs, and checks that memstore size is decreased
   * as older keyvalues are deleted from the memstore.
   * @throws Exception
   */
  @Test
  public void testUpsertMemstoreSize() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    memstore = new DefaultMemStore(conf, CellComparatorImpl.COMPARATOR);
    MemStoreSize oldSize = memstore.size();

    List<Cell> l = new ArrayList<>();
    KeyValue kv1 = KeyValueTestUtil.create("r", "f", "q", 100, "v");
    KeyValue kv2 = KeyValueTestUtil.create("r", "f", "q", 101, "v");
    KeyValue kv3 = KeyValueTestUtil.create("r", "f", "q", 102, "v");

    kv1.setSequenceId(1); kv2.setSequenceId(1);kv3.setSequenceId(1);
    l.add(kv1); l.add(kv2); l.add(kv3);

    this.memstore.upsert(l, 2, null);// readpoint is 2
    MemStoreSize newSize = this.memstore.size();
    assert (newSize.getDataSize() > oldSize.getDataSize());
    //The kv1 should be removed.
    assert(memstore.getActive().getCellsCount() == 2);

    KeyValue kv4 = KeyValueTestUtil.create("r", "f", "q", 104, "v");
    kv4.setSequenceId(1);
    l.clear(); l.add(kv4);
    this.memstore.upsert(l, 3, null);
    assertEquals(newSize, this.memstore.size());
    //The kv2 should be removed.
    assert(memstore.getActive().getCellsCount() == 2);
    //this.memstore = null;
  }

  ////////////////////////////////////
  // Test for periodic memstore flushes
  // based on time of oldest edit
  ////////////////////////////////////

  /**
   * Tests that the timeOfOldestEdit is updated correctly for the
   * various edit operations in memstore.
   * @throws Exception
   */
  @Test
  public void testUpdateToTimeOfOldestEdit() throws Exception {
    try {
      EnvironmentEdgeForMemstoreTest edge = new EnvironmentEdgeForMemstoreTest();
      EnvironmentEdgeManager.injectEdge(edge);
      DefaultMemStore memstore = new DefaultMemStore();
      long t = memstore.timeOfOldestEdit();
      assertEquals(Long.MAX_VALUE, t);

      // test the case that the timeOfOldestEdit is updated after a KV add
      memstore.add(KeyValueTestUtil.create("r", "f", "q", 100, "v"), null);
      t = memstore.timeOfOldestEdit();
      assertTrue(t == 1234);
      // snapshot() will reset timeOfOldestEdit. The method will also assert the
      // value is reset to Long.MAX_VALUE
      t = runSnapshot(memstore);

      // test the case that the timeOfOldestEdit is updated after a KV delete
      memstore.add(KeyValueTestUtil.create("r", "f", "q", 100, KeyValue.Type.Delete, "v"), null);
      t = memstore.timeOfOldestEdit();
      assertTrue(t == 1234);
      t = runSnapshot(memstore);

      // test the case that the timeOfOldestEdit is updated after a KV upsert
      List<Cell> l = new ArrayList<>();
      KeyValue kv1 = KeyValueTestUtil.create("r", "f", "q", 100, "v");
      kv1.setSequenceId(100);
      l.add(kv1);
      memstore.upsert(l, 1000, null);
      t = memstore.timeOfOldestEdit();
      assertTrue(t == 1234);
    } finally {
      EnvironmentEdgeManager.reset();
    }
  }

  /**
   * Tests the HRegion.shouldFlush method - adds an edit in the memstore
   * and checks that shouldFlush returns true, and another where it disables
   * the periodic flush functionality and tests whether shouldFlush returns
   * false.
   * @throws Exception
   */
  @Test
  public void testShouldFlush() throws Exception {
    Configuration conf = new Configuration();
    conf.setInt(HRegion.MEMSTORE_PERIODIC_FLUSH_INTERVAL, 1000);
    checkShouldFlush(conf, true);
    // test disable flush
    conf.setInt(HRegion.MEMSTORE_PERIODIC_FLUSH_INTERVAL, 0);
    checkShouldFlush(conf, false);
  }

  protected void checkShouldFlush(Configuration conf, boolean expected) throws Exception {
    try {
      EnvironmentEdgeForMemstoreTest edge = new EnvironmentEdgeForMemstoreTest();
      EnvironmentEdgeManager.injectEdge(edge);
      HBaseTestingUtility hbaseUtility = HBaseTestingUtility.createLocalHTU(conf);
      String cf = "foo";
      HRegion region =
          hbaseUtility.createTestRegion("foobar", ColumnFamilyDescriptorBuilder.of(cf));

      edge.setCurrentTimeMillis(1234);
      Put p = new Put(Bytes.toBytes("r"));
      p.add(KeyValueTestUtil.create("r", cf, "q", 100, "v"));
      region.put(p);
      edge.setCurrentTimeMillis(1234 + 100);
      StringBuilder sb = new StringBuilder();
      assertTrue(!region.shouldFlush(sb));
      edge.setCurrentTimeMillis(1234 + 10000);
      assertTrue(region.shouldFlush(sb) == expected);
    } finally {
      EnvironmentEdgeManager.reset();
    }
  }

  @Test
  public void testShouldFlushMeta() throws Exception {
    // write an edit in the META and ensure the shouldFlush (that the periodic memstore
    // flusher invokes) returns true after SYSTEM_CACHE_FLUSH_INTERVAL (even though
    // the MEMSTORE_PERIODIC_FLUSH_INTERVAL is set to a higher value)
    Configuration conf = new Configuration();
    conf.setInt(HRegion.MEMSTORE_PERIODIC_FLUSH_INTERVAL, HRegion.SYSTEM_CACHE_FLUSH_INTERVAL * 10);
    HBaseTestingUtility hbaseUtility = HBaseTestingUtility.createLocalHTU(conf);
    Path testDir = hbaseUtility.getDataTestDir();
    EnvironmentEdgeForMemstoreTest edge = new EnvironmentEdgeForMemstoreTest();
    EnvironmentEdgeManager.injectEdge(edge);
    edge.setCurrentTimeMillis(1234);
    WALFactory wFactory = new WALFactory(conf, "1234");
    HRegion meta = HRegion.createHRegion(RegionInfoBuilder.FIRST_META_REGIONINFO, testDir,
        conf, FSTableDescriptors.createMetaTableDescriptor(conf),
        wFactory.getWAL(RegionInfoBuilder.FIRST_META_REGIONINFO));
    // parameterized tests add [#] suffix get rid of [ and ].
    TableDescriptor desc = TableDescriptorBuilder
        .newBuilder(TableName.valueOf(name.getMethodName().replaceAll("[\\[\\]]", "_")))
        .setColumnFamily(ColumnFamilyDescriptorBuilder.of("foo")).build();
    RegionInfo hri = RegionInfoBuilder.newBuilder(desc.getTableName())
        .setStartKey(Bytes.toBytes("row_0200")).setEndKey(Bytes.toBytes("row_0300")).build();
    HRegion r = HRegion.createHRegion(hri, testDir, conf, desc, wFactory.getWAL(hri));
    addRegionToMETA(meta, r);
    edge.setCurrentTimeMillis(1234 + 100);
    StringBuilder sb = new StringBuilder();
    assertTrue(meta.shouldFlush(sb) == false);
    edge.setCurrentTimeMillis(edge.currentTime() + HRegion.SYSTEM_CACHE_FLUSH_INTERVAL + 1);
    assertTrue(meta.shouldFlush(sb) == true);
  }

  /**
   * Inserts a new region's meta information into the passed
   * <code>meta</code> region. Used by the HMaster bootstrap code adding
   * new table to hbase:meta table.
   *
   * @param meta hbase:meta HRegion to be updated
   * @param r HRegion to add to <code>meta</code>
   *
   * @throws IOException
   */
  public static void addRegionToMETA(final HRegion meta, final HRegion r) throws IOException {
    meta.checkResources();
    // The row key is the region name
    byte[] row = r.getRegionInfo().getRegionName();
    final long now = EnvironmentEdgeManager.currentTime();
    final List<Cell> cells = new ArrayList<>(2);
    cells.add(new KeyValue(row, HConstants.CATALOG_FAMILY,
      HConstants.REGIONINFO_QUALIFIER, now, RegionInfo.toByteArray(r.getRegionInfo())));
    // Set into the root table the version of the meta table.
    cells.add(new KeyValue(row, HConstants.CATALOG_FAMILY,
      HConstants.META_VERSION_QUALIFIER, now,
      Bytes.toBytes(HConstants.META_VERSION)));
    meta.put(row, HConstants.CATALOG_FAMILY, cells);
  }

  private class EnvironmentEdgeForMemstoreTest implements EnvironmentEdge {
    long t = 1234;
    @Override
    public long currentTime() {
      return t;
    }
    public void setCurrentTimeMillis(long t) {
      this.t = t;
    }
  }

  /**
   * Adds {@link #ROW_COUNT} rows and {@link #QUALIFIER_COUNT}
   * @param hmc Instance to add rows to.
   * @return How many rows we added.
   * @throws IOException
   */
  protected int addRows(final AbstractMemStore hmc) {
    return addRows(hmc, HConstants.LATEST_TIMESTAMP);
  }

  /**
   * Adds {@link #ROW_COUNT} rows and {@link #QUALIFIER_COUNT}
   * @param hmc Instance to add rows to.
   * @return How many rows we added.
   * @throws IOException
   */
  protected int addRows(final MemStore hmc, final long ts) {
    for (int i = 0; i < ROW_COUNT; i++) {
      long timestamp = ts == HConstants.LATEST_TIMESTAMP ?
        System.currentTimeMillis() : ts;
      for (int ii = 0; ii < QUALIFIER_COUNT; ii++) {
        byte [] row = Bytes.toBytes(i);
        byte [] qf = makeQualifier(i, ii);
        hmc.add(new KeyValue(row, FAMILY, qf, timestamp, qf), null);
      }
    }
    return ROW_COUNT;
  }

  private long runSnapshot(final AbstractMemStore hmc) throws UnexpectedStateException {
    // Save off old state.
    int oldHistorySize = hmc.getSnapshot().getCellsCount();
    MemStoreSnapshot snapshot = hmc.snapshot();
    // Make some assertions about what just happened.
    assertTrue("History size has not increased", oldHistorySize < hmc.getSnapshot().getCellsCount
        ());
    long t = memstore.timeOfOldestEdit();
    assertTrue("Time of oldest edit is not Long.MAX_VALUE", t == Long.MAX_VALUE);
    hmc.clearSnapshot(snapshot.getId());
    return t;
  }

  private void isExpectedRowWithoutTimestamps(final int rowIndex,
      List<Cell> kvs) {
    int i = 0;
    for (Cell kv : kvs) {
      byte[] expectedColname = makeQualifier(rowIndex, i++);
      assertTrue("Column name", CellUtil.matchingQualifier(kv, expectedColname));
      // Value is column name as bytes.  Usually result is
      // 100 bytes in size at least. This is the default size
      // for BytesWriteable.  For comparison, convert bytes to
      // String and trim to remove trailing null bytes.
      assertTrue("Content", CellUtil.matchingValue(kv, expectedColname));
    }
  }

  private static void addRows(int count, final MemStore mem) {
    long nanos = System.nanoTime();

    for (int i = 0 ; i < count ; i++) {
      if (i % 1000 == 0) {

        System.out.println(i + " Took for 1k usec: " + (System.nanoTime() - nanos)/1000);
        nanos = System.nanoTime();
      }
      long timestamp = System.currentTimeMillis();

      for (int ii = 0; ii < QUALIFIER_COUNT ; ii++) {
        byte [] row = Bytes.toBytes(i);
        byte [] qf = makeQualifier(i, ii);
        mem.add(new KeyValue(row, FAMILY, qf, timestamp, qf), null);
      }
    }
  }

  static void doScan(MemStore ms, int iteration) throws IOException {
    long nanos = System.nanoTime();
    KeyValueScanner s = ms.getScanners(0).get(0);
    s.seek(KeyValueUtil.createFirstOnRow(new byte[]{}));

    System.out.println(iteration + " create/seek took: " + (System.nanoTime() - nanos)/1000);
    int cnt=0;
    while(s.next() != null) ++cnt;

    System.out.println(iteration + " took usec: " + (System.nanoTime() - nanos) / 1000 + " for: "
        + cnt);

  }

  public static void main(String [] args) throws IOException {
    MemStore ms = new DefaultMemStore();

    long n1 = System.nanoTime();
    addRows(25000, ms);
    System.out.println("Took for insert: " + (System.nanoTime()-n1)/1000);

    System.out.println("foo");

    for (int i = 0 ; i < 50 ; i++)
      doScan(ms, i);
  }
}


text:
'use strict';

exports = module.exports = function(app, passport) {
    var LocalStrategy = require('passport-local').Strategy,
        TwitterStrategy = require('passport-twitter').Strategy,
        GitHubStrategy = require('passport-github').Strategy,
        FacebookStrategy = require('passport-facebook').Strategy,
        GoogleStrategy = require('passport-google-oauth').OAuth2Strategy,
        TumblrStrategy = require('passport-tumblr').Strategy;

    passport.use(new LocalStrategy(
        function(username, password, done) {
            var conditions = {
                isActive: 'yes'
            };
            if (username.indexOf('@') === -1) {
                conditions.username = username;
            } else {
                conditions.email = username.toLowerCase();
            }

            app.db.User.findOne(conditions).then(function(user) {
                    if (!user) {
                        return done(null, false, {
                            message: 'Unknown user'
                        });
                    }
                    app.db.User.validatePassword(password, user.password, function(err, isValid) {
                        if (err) {
                            return done(err);
                        }

                        if (!isValid) {
                            return done(null, false, {
                                message: 'Invalid password'
                            });
                        }
                        return done(null, user);
                    });
                })
                .catch(function(err) {
                    return done(err);
                });
        }
    ));

    if (app.config.oauth.twitter.key) {
        passport.use(new TwitterStrategy({
                consumerKey: app.config.oauth.twitter.key,
                consumerSecret: app.config.oauth.twitter.secret
            },
            function(token, tokenSecret, profile, done) {
                done(null, false, {
                    token: token,
                    tokenSecret: tokenSecret,
                    profile: profile
                });
            }
        ));
    }

    if (app.config.oauth.github.key) {
        passport.use(new GitHubStrategy({
                clientID: app.config.oauth.github.key,
                clientSecret: app.config.oauth.github.secret,
                customHeaders: {
                    "User-Agent": app.config.projectName
                }
            },
            function(accessToken, refreshToken, profile, done) {
                done(null, false, {
                    accessToken: accessToken,
                    refreshToken: refreshToken,
                    profile: profile
                });
            }
        ));
    }

    if (app.config.oauth.facebook.key) {
        passport.use(new FacebookStrategy({
                clientID: app.config.oauth.facebook.key,
                clientSecret: app.config.oauth.facebook.secret
            },
            function(accessToken, refreshToken, profile, done) {
                done(null, false, {
                    accessToken: accessToken,
                    refreshToken: refreshToken,
                    profile: profile
                });
            }
        ));
    }

    if (app.config.oauth.google.key) {
        passport.use(new GoogleStrategy({
                clientID: app.config.oauth.google.key,
                clientSecret: app.config.oauth.google.secret
            },
            function(accessToken, refreshToken, profile, done) {
                done(null, false, {
                    accessToken: accessToken,
                    refreshToken: refreshToken,
                    profile: profile
                });
            }
        ));
    }

    if (app.config.oauth.tumblr.key) {
        passport.use(new TumblrStrategy({
                consumerKey: app.config.oauth.tumblr.key,
                consumerSecret: app.config.oauth.tumblr.secret
            },
            function(token, tokenSecret, profile, done) {
                done(null, false, {
                    token: token,
                    tokenSecret: tokenSecret,
                    profile: profile
                });
            }
        ));
    }

    passport.serializeUser(function(user, done) {
        done(null, user.id);
    });

    passport.deserializeUser(function(id, done) {
        app.db.User.findOne({
                id: id
            })
            .then(function(user) {
                done(null, user);
            })
            .catch(function(err) {
                console.log('Error de-serializing ', err);
                done(err);
            });
    });

};


text:
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @ts-nocheck
// TODO(crbug.com/1011811): Enable TypeScript compiler checks

import * as Common from '../common/common.js';
import {ActionDelegate} from './ActionDelegate.js';  // eslint-disable-line no-unused-vars

/**
 * @unrestricted
 */
export class Action extends Common.ObjectWrapper.ObjectWrapper {
  /**
   * @param {!Root.Runtime.Extension} extension
   */
  constructor(extension) {
    super();
    this._extension = extension;
    this._enabled = true;
    this._toggled = false;
  }

  /**
   * @return {string}
   */
  id() {
    return this._extension.descriptor()['actionId'];
  }

  /**
   * @return {!Root.Runtime.Extension}
   */
  extension() {
    return this._extension;
  }

  /**
   * @return {!Promise.<boolean>}
   */
  async execute() {
    if (!this._extension.canInstantiate()) {
      return false;
    }
    const delegate = /** @type {!ActionDelegate} */ (await this._extension.instance());
    const actionId = this.id();
    return delegate.handleAction(self.UI.context, actionId);
  }

  /**
   * @return {string}
   */
  icon() {
    return this._extension.descriptor()['iconClass'] || '';
  }

  /**
   * @return {string}
   */
  toggledIcon() {
    return this._extension.descriptor()['toggledIconClass'] || '';
  }

  /**
   * @return {boolean}
   */
  toggleWithRedColor() {
    return !!this._extension.descriptor()['toggleWithRedColor'];
  }

  /**
   * @param {boolean} enabled
   */
  setEnabled(enabled) {
    if (this._enabled === enabled) {
      return;
    }

    this._enabled = enabled;
    this.dispatchEventToListeners(Events.Enabled, enabled);
  }

  /**
   * @return {boolean}
   */
  enabled() {
    return this._enabled;
  }

  /**
   * @return {string}
   */
  category() {
    return ls(this._extension.descriptor()['category'] || '');
  }

  /**
   * @return {string}
   */
  tags() {
    return this._extension.descriptor()['tags'] || '';
  }

  /**
   * @return {boolean}
   */
  toggleable() {
    return !!this._extension.descriptor()['toggleable'];
  }

  /**
   * @return {string}
   */
  title() {
    let title = this._extension.title() || '';
    const options = this._extension.descriptor()['options'];
    if (options) {
      for (const pair of options) {
        if (pair['value'] !== this._toggled) {
          title = ls(pair['title']);
        }
      }
    }
    return title;
  }

  /**
   * @return {boolean}
   */
  toggled() {
    return this._toggled;
  }

  /**
   * @param {boolean} toggled
   */
  setToggled(toggled) {
    console.assert(this.toggleable(), 'Shouldn\'t be toggling an untoggleable action', this.id());
    if (this._toggled === toggled) {
      return;
    }

    this._toggled = toggled;
    this.dispatchEventToListeners(Events.Toggled, toggled);
  }
}

/** @enum {symbol} */
export const Events = {
  Enabled: Symbol('Enabled'),
  Toggled: Symbol('Toggled')
};