<commit_before>'use strict';

import {AbstractFsDriver} from '../../lib/Driver/AbstractFsDriver';
import {NoFlushException} from '../../lib/Driver/Exception/NoFlushException';
import {DriverException} from '../../lib/Driver/Exception/DriverException';

export class AbstractFsDriverMock extends AbstractFsDriver {
  /**
   * @param args
   */
  constructor(directory = AbstractFsDriver.DEFAULT_DIRECTORY) {
    super(directory);
    this.disableFailureMode();
  }

  /**
   * Enables failure mode
   */
  enableFailureMode() {
    this.isFailureEnabled = true;
    this.error = AbstractFsDriverMock.ERROR;
    this.data = null;
  }

  /**
   * Disables failure mode
   */
  disableFailureMode() {
    this.isFailureEnabled = false;
    this.error = null;
    this.data = AbstractFsDriverMock.DATA;
  }

  /**
   * @param {String} key
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _get(key, callback = null) {
    callback(this.error, this.data);

    return this;
  }

  /**
   * @param {String} key
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _has(key, callback = null) {
    callback(this.error, this.data);

    return this;
  }

  /**
   * @param {String} key
   * @param {Number} timeout
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _invalidate(key, timeout = 0, callback = null) {
    callback(this.error, this.data);

    return this;
  }

  /**
   * @param {String} key
   * @param {*} value
   * @param {Number} ttl
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _set(key, value, ttl = 0, callback = null) {
    if (this.isFailureEnabled === true) {
      throw new DriverException('Implicitly test Driver Exception');
    } else {
      callback(this.error, this.data);
    }

    return this;
  }

  /**
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _flush(callback = null) {
    if (this.isFailureEnabled === true) {
      throw new NoFlushException();
    } else {
      callback(this.error, this.data);
    }

    return this;
  }

  /**
   * @returns {{code: number, message: string}}
   * @constructor
   */
  static get ERROR() {
    return {
      code: 500,
      message: 'Internal Error',
    };
  }

  /**
   * @returns {{data: string}}
   * @constructor
   */
  static get DATA() {
    return {
      data: 'Valid test data',
    };
  }
}
<commit_msg>#186: Fix deep-cache test errors<commit_after>'use strict';

import {AbstractFsDriver} from '../../lib/Driver/AbstractFsDriver';
import {NoFlushException} from '../../lib/Driver/Exception/NoFlushException';
import {DriverException} from '../../lib/Driver/Exception/DriverException';

export class AbstractFsDriverMock extends AbstractFsDriver {
  /**
   * @param args
   */
  constructor(directory = AbstractFsDriver.DEFAULT_DIRECTORY) {
    super(directory);
    this.disableFailureMode();
  }

  /**
   * Enables failure mode
   */
  enableFailureMode() {
    this.isFailureEnabled = true;
    this.error = AbstractFsDriverMock.ERROR;
    this.data = null;
  }

  /**
   * Disables failure mode
   */
  disableFailureMode() {
    this.isFailureEnabled = false;
    this.error = null;
    this.data = AbstractFsDriverMock.DATA;
  }

  /**
   * @param {String} key
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _get(key, callback = null) {
    callback(this.error, this.data);

    return this;
  }

  /**
   * @returns {String}
   * @private
   */
  _type() {
    return 'S3FS';
  }

  /**
   * @param {String} key
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _has(key, callback = null) {
    callback(this.error, this.data);

    return this;
  }

  /**
   * @param {String} key
   * @param {Number} timeout
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _invalidate(key, timeout = 0, callback = null) {
    callback(this.error, this.data);

    return this;
  }

  /**
   * @param {String} key
   * @param {*} value
   * @param {Number} ttl
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _set(key, value, ttl = 0, callback = null) {
    if (this.isFailureEnabled === true) {
      throw new DriverException('Implicitly test Driver Exception');
    } else {
      callback(this.error, this.data);
    }

    return this;
  }

  /**
   * @param {Function} callback
   * @returns {AbstractFsDriverMock}
   * @private
   */
  _flush(callback = null) {
    if (this.isFailureEnabled === true) {
      throw new NoFlushException();
    } else {
      callback(this.error, this.data);
    }

    return this;
  }

  /**
   * @returns {{code: number, message: string}}
   * @constructor
   */
  static get ERROR() {
    return {
      code: 500,
      message: 'Internal Error',
    };
  }

  /**
   * @returns {{data: string}}
   * @constructor
   */
  static get DATA() {
    return {
      data: 'Valid test data',
    };
  }
}

{'fraction_non_alphanumeric': 0.14669016842929886, 'fraction_numerical': 0.0027418723070896985, 'mean_word_length': 2.621985815602837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2645089', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1634, 'n_words': 366}